Help with Sessions

Discussion in 'PHP' started by WhitneyM, Nov 25, 2009.

  1. #1
    So I am trying to use sessions on my pages, with my index page if you log in and your username and password are recognized the user gets directed to the home page, if the session does not exist on the home page the user is redirected to the index page to login, if the session exists the user stays on the home page. I keep getting directed back to the index page after the home page. I couldn't find anything wrong with the script so I did a test page. I named the first one 1.php and the second 2.php here are the scripts:

    Page 1:
    <?php
    session_start();
    $_session['color']="orange";
    $_session['auth']="yes";
    ?>
    <html>
    <p>This is page one, color should be set to orange, auth should be set to yes.
    <a href="2.php?">Click to go to the second page</a></p>
    </html>

    Page 2:
    <?Php
    $session_start();
    echo"color=";
    echo $_session['color'];
    echo"auth=";
    echo $_session['auth'];
    ?>

    Page one works fine and the html statement shows up, when I click on the link it takes me to the second page and this is the error i get:
    Fatal error: Function name must be a string in C:\AppServ\www\2.php on line 2
    I don't know what that means, am I supposed to put something in the () at the end of session start?
     
    WhitneyM, Nov 25, 2009 IP
  2. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Looks like it's a careless typo. Did you notice you put a dollar sign in front of session_start?

    <?php
    session_start();
    echo "color=";
    echo $_SESSION['color'];
    echo "auth=";
    echo $_SESSION['auth'];
    ?>
    PHP:
    Would be better if you replace your $_session with $_SESSION.
     
    ads2help, Nov 25, 2009 IP
  3. kbduvall

    kbduvall Peon

    Messages:
    71
    Likes Received:
    3
    Best Answers:
    4
    Trophy Points:
    0
    #3
    Yes, variables in PHP are case sensitive so $_SESSION is not the same as $_session. $_SESSION is the correct array to access session data.

    And of course remove the $ from session_start();
     
    kbduvall, Nov 27, 2009 IP