Page 1 of 1

sessions lost

Posted: Thu Feb 22, 2007 11:17 pm
by nwp
My sessions are being lost i donno why
-----------------------------------------------------
First I am using thjis code to set the session variables

Code: Select all

<?php
header("Content-Type: text/plain");
session_start();
$_SESSION["Name"] = "Hello";
echo session_id()."\n";
print_r($_SESSION);
?>
and this works and sets the session vars

and then using this code to get the values of the session variables

Code: Select all

<?php
header("Content-Type: text/plain");
//session_start();
//$_SESSION["Name"] = "Hello";
echo session_id()."\n";
print_r($_SESSION);
?>
But its just going blank but browser shows that there are PHPSESID Cookie Stored in the browser although session_id() is not showing anything its acting as $_SESSION is not set

Posted: Thu Feb 22, 2007 11:33 pm
by dude81
you missed session_start there

Posted: Thu Feb 22, 2007 11:36 pm
by nwp
But If I use the session_start() there the previously created sesions get lost

Posted: Thu Feb 22, 2007 11:39 pm
by dude81
You need to use session_start() in every page you are using session variables

Posted: Thu Feb 22, 2007 11:42 pm
by nwp
OK thanks for your reply i am testing it