Question:

Lang: php var name:$id issue:session not staying registered?

by  |  earlier

0 LIKES UnLike

page 1:

<?php

//register any session vairables

session_start();

session_register("id");

$id=$row["id"];

?>

page 2:

<?php

session_start();

$_SESSION['id'];//creates session variable

//check to see if the user is logged in this will be done each time on any internal page

Print_r ($_SESSION);

?>

output:

Array ( [id] => 1 [] => )

Why won't it keep me logged in?

 Tags:

   Report

2 ANSWERS


  1. geek,

    try setting $id=$row[&quot;id&quot;];

    before calling session_register(&quot;id&quot;);

    Also, this is from Php.net:

    // Use of session_register() is deprecated

    $barney = &quot;A big purple dinosaur.&quot;;

    session_register(&quot;barney&quot;);

    // Use of $_SESSION is preferred, as of PHP 4.1.0

    $_SESSION[&quot;zim&quot;] = &quot;An invader from another planet.&quot;;


  2. For a start you are declaring a variable in one page, then re-decalring it on the second page, this would clear it. Better is :

    &lt;?php

    session_start();

    $_SESSION[id] = whatever you want.

    ?&gt;

    In any further pages you can simply read it :

    &lt;?php

    $[id] = $_SESSION[id];

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.