HELPP : session not working !!

Discussion in 'PHP' started by GimanaDong, May 10, 2006.

  1. #1
    these are my php files that show my script about session :

    test.php
    <?
    session_start();
    session_register("testVar");
    $testVar = "HI PHP";
    header("Location:test2.php");
    ?>

    tes2.php
    <?
    session_start();
    echo $testVar;
    ?>

    the problem is, the browser don't show anything when i run test.php.
    i check my tmp folder (c:\apache\tmp\),and there are 2 files session id that been created, BUT one file save the variable, and other doesn't. and the last file created is the one without any content.

    i'm sorry if my english is mess, i can't write english well.
    thanx
     
    GimanaDong, May 10, 2006 IP
  2. themole

    themole Peon

    Messages:
    82
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    session_register() is deprecated (no longer used), and Register Globals isn't on. Try this:

    test.php
    <?
    session_start();
    $_SESSION[testVar] = "HI PHP";
    header("Location:test2.php");
    ?>

    test2.php
    <?
    session_start();
    echo $_SESSION[testVar];
    ?>

    -the mole
     
    themole, May 10, 2006 IP
  3. GimanaDong

    GimanaDong Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i've tried that script to... but it still didn't worked out.
    i don't know if this because of my PHP.ini settings or not, b'cause before i formatted my computer, it's worked well.

    i've tried to change the header(location:....) with <a href=... > </a> and the session is working... but in the url my session id is shown.
     
    GimanaDong, May 10, 2006 IP
  4. ahref

    ahref Well-Known Member

    Messages:
    1,123
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    170
    #4
    I checked above script it is displaying the value of $testvar. But session_start on test2.php is creating problem, instead of header("Location:test2.php"); use < a href ="" then it will work fine
     
    ahref, May 11, 2006 IP
  5. tech86

    tech86 Peon

    Messages:
    83
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    php.net/manual/en/function.session-start.php

    stop treating these forums as clutches.. the information is very freely available on google and the php.net documentation..


    <?php
    // page1.php

    session_start();

    echo 'Welcome to page #1';

    $_SESSION['favcolor'] = 'green';
    $_SESSION['animal'] = 'cat';
    $_SESSION['time'] = time();

    // Works if session cookie was accepted
    echo '<br /><a href="page2.php">page 2</a>';

    // Or maybe pass along the session id, if needed
    echo '<br /><a href="page2.php?' . SID . '">page 2</a>';
    ?>
     
    tech86, May 11, 2006 IP