Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15

Thread: Sessions?

  1. #1
    Regular Coder
    Join Date
    May 2006
    Location
    Canada
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Sessions?

    PHP Code:
    if(!$_SESSION['logged_in'] {
    header("Location: http://www.thugkillin.urlshort.com/base.php");


    what im to do is trying to make it so people can just go to http://www.thugkillin.urlshort.com/base.php without being signed in!?


    Rawli
    Rawli

  • #2
    Regular Coder
    Join Date
    Sep 2005
    Posts
    394
    Thanks
    1
    Thanked 0 Times in 0 Posts
    You need another ) and you should probably use isset, i.e.

    PHP Code:
    if(!isset($_SESSION['logged_in'])) { 
    header("Location: http://www.thugkillin.urlshort.com/base.php"); 


  • #3
    Regular Coder
    Join Date
    May 2006
    Location
    Canada
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php
    if(!isset($_SESSION['logged_in'])) {  
    header("Location: http://www.thugkillin.urlshort.com/base.php");  
    }
    ?>

    didnt work it says a warning!

    Warning: Cannot modify header information - headers already sent by (output started at /home/thug/public_html/base.php:2) in /home/thug/public_html/base.php on line 4


    and this is the script of the top?
    for my base.php

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <?php
    if(!isset($_SESSION['logged_in'])) {  
    header("Location: http://www.thugkillin.urlshort.com/base.php");  
    }
    ?>
    Last edited by RawliJr; 06-19-2006 at 11:51 PM.
    Rawli

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    You cannot send a header to the client after you have sent anything else. That means you need to call the header function before any HTML gets sent to the client browser.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    you have to put
    PHP Code:
    session_start() 
    at the top of the page before any echos or html

  • #6
    Regular Coder
    Join Date
    May 2006
    Location
    Canada
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs down ok?

    PHP Code:
    <?php
    session_start
    ()
    if(!isset(
    $_SESSION['logged_in'])) {  
    header("Location: http://www.thugkillin.urlshort.com/base.php");  
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Main Menu</title>
    <style type="text/css">
    html, body {
    margin:0;
    padding:0;
    background:#000;
    color:#FFF;
    }
    .eric {
        height: 400px;
        width: 200px;
        border: 3px solid red;
        background: blue;
        color:#FFF;
        float:left;
    }
    .rawli {
        height: 400px;
        width: 200px;
        border: 3px solid red;
        background: blue;
        float: right;
    }
    a:link {color: #FF0000;background-color:inherit;}
    a:visited {color: #00FF00;background-color:inherit;}
    a:hover {color: #FF00FF;background-color:inherit;}
    a:active {color: #0000FF;background-color:inherit;}
    </style>
    </head>
    <center><img src="/images/THUGKILLIN.jpg" border="0" width="444" /></a></center>
    <?php  
    $link 
    mysql_connect("localhost","xxx","xxx") or die("No connection");   
    mysql_select_db("xxx",$link) or die("Bad Database");  
    $rec_query "SELECT * FROM users WHERE username='$thisusername'"
    $rec_res mysql_query($rec_query) or die(mysql_error()); 
    $rec mysql_fetch_array($rec_res); 
    $getid $rec['id'];  
    echo 
    "$getid";
    echo 
    "$rec_query";
    ?>
    <body>
    <div class="eric">
    <a href="turntrick.php">Turn Tricks</a>
    <br><br>
    <a href=">forums.php">Forums</a>
    <br><br>
    <a href="getturns.php">Buy Turns</a>
    <br><br>
    <a href="attackrank.php">Attack Ranks</a>
    <br><br>
    <a href="cityr.php">City Ranks</a>
    </div>
    <div class="rawli">
    <a href="naranks.php">National Ranks</a>
    <br><br>
    <a href="store.php">Corner Store</a>
    <br><br>
    <a href="faqs.html">Faqs</a>
    <br><br>
    <a href="logout.php">Log out</a>
    </div>
    </body>
    </html>
    ^that is my base.php^

    and that doesnt work?

    it says on the browser
    Parse error: syntax error, unexpected T_IF in /home/thug/public_html/base.php on line 3
    Rawli

  • #7
    Regular Coder
    Join Date
    Sep 2005
    Posts
    394
    Thanks
    1
    Thanked 0 Times in 0 Posts
    This is SIMPLE stuff! Just look over your code before posting. You missed a ; after session_start().

    ~Phil~

  • #8
    Regular Coder
    Join Date
    May 2006
    Location
    Canada
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs down Thanx

    But now it still doesnt work, like it when i try adn login at the main menu page...it just wont load?


    PHP Code:
    <?php
    session_start
    ();
    if(!isset(
    $_SESSION['logged_in'])) {  
    header("Location: http://www.thugkillin.urlshort.com/base.php");  
    }
    ?>
    then if i take out all the php it works fine?

    not sure what is wrong?And all of it is at the top of my script so ?

    cheers
    rawli
    Rawli

  • #9
    due
    due is offline
    New Coder
    Join Date
    May 2006
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    try this

    try this
    PHP Code:
    <?
        session_start
    ();
        
    $_SESSION['logged_in']=0;
        
    header("Location: http://www.thugkillin.urlshort.com/base.php"); 
    ?>
    DUE

  • #10
    Regular Coder
    Join Date
    May 2006
    Location
    Canada
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts
    nope

    thanx anyways
    Rawli

  • #11
    Regular Coder
    Join Date
    May 2006
    Location
    Canada
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    like would anybody know the code that if your not logged in, you can visit that page?

    That would be very much help full if you do!

    beacuse this isnt working, or im missing something

    PHP Code:
    <?php 
    session_start
    (); 
    if(!isset(
    $_SESSION['logged_in'])) {   
    header("Location: http://www.thugkillin.urlshort.com/base.php");   

    ?>
    Cheers
    Rawli
    Rawli

  • #12
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    With the code you have there if the session variable logged_in has not yet been set then the user will be redirected to the file base.php. You want them to go to base.php when they are not logged in correct? As for logging in you are actually giving the logged_in session variable a value in your code that authenticates the login correct?
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #13
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Is it possible that you are coming in on a different page ?
    ALL pages would need to have that code, not just your "base page"
    --
    just a thought
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #14
    Regular Coder
    Join Date
    May 2006
    Location
    Canada
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb

    Quote Originally Posted by Spookster
    You want them to go to base.php when they are not logged in correct?

    no im trying to do , is that when people arnt logged in they cant go passed the index.php, and when they log in it takes them to the base.php, SO people cant just go to the BASE with out being logged in..?

    and i dont know how to do that?

    cheers
    rawli
    Rawli

  • #15
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by RawliJr
    like would anybody know the code that if your not logged in, you can visit that page?

    That would be very much help full if you do!

    beacuse this isnt working, or im missing something

    PHP Code:
    <?php 
    session_start
    (); 
    if(!isset(
    $_SESSION['logged_in'])) {   
    header("Location: http://www.thugkillin.urlshort.com/base.php");   

    ?>
    Cheers
    Rawli
    what i can see here, if you want the user to go to http://www.thugkillin.urlshort.com/base.php if they are logged in then i think its should be the code below, because i believe the above code is saying if they aint logged in go to http://www.thugkillin.urlshort.com/base.php

    PHP Code:
    <?php 
    session_start
    (); 
    if(isset(
    $_SESSION['logged_in'])) {   
    header("Location: http://www.thugkillin.urlshort.com/base.php");   
    } else {
    header("Location: http://www.thugkillin.urlshort.com/login.php");
    ?>
    but i could be wrong

    paulley
    Last edited by paulley; 06-25-2006 at 01:42 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •