sessions lost

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nwp
Forum Contributor
Posts: 105
Joined: Sun Feb 04, 2007 12:25 pm

sessions lost

Post 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
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

you missed session_start there
nwp
Forum Contributor
Posts: 105
Joined: Sun Feb 04, 2007 12:25 pm

Post by nwp »

But If I use the session_start() there the previously created sesions get lost
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

You need to use session_start() in every page you are using session variables
nwp
Forum Contributor
Posts: 105
Joined: Sun Feb 04, 2007 12:25 pm

Post by nwp »

OK thanks for your reply i am testing it
Post Reply