Session variables help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • learnPHP
    New Member
    • Mar 2008
    • 20

    Session variables help

    Hi ,

    I am back with another small problem:

    I want to create a session in which i want to declare a session variable. I want to use the value of that session variable on the next two pages. This is the code that i have.

    1st page:[CODE=php]<?PHP
    session_start() ;
    session_registe r ("demo");
    if($_SERVER['HTTP_REFERER'] == "http://localhost/FAO_test/firms_WEB/Untitled-6.php")
    {
    $test=1;
    $_SESSION["demo"]= $test;
    }
    ?>
    [/CODE]2nd page
    [CODE=php]<?PHP
    session_start() ;
    if ($_SESSION['demo']== 1)
    include ("Untitled-7.php");
    ?>
    [/CODE]
    3rd page
    [CODE=php]<?PHP
    session_start() ;
    if ($_SESSION['demo']== 1)
    include ("Untitled-7.php");
    ?>[/CODE]But the problem is that the value of demo is not registering and i dont think the if statement in the 2nd and 3rd page is working. It displays the UNtitled-7.php even if demos value is not 1.

    Please tell me what i am doing wrong??
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    You have:[CODE=php]if ($_SESSION['demo']== 1)
    include ("Untitled-7.php");[/CODE]

    Should be:[CODE=php]if ($_SESSION['demo']== 1) {
    include ("Untitled-7.php");
    }[/CODE]


    Also is there any specific reason you are using session_registe r? You can just have: $_SESSION['demo'] = $test; instead of registering it and then giving it a value?

    Comment

    Working...