Click to See Complete Forum and Search --> : $_SESSION not working PHP


miteshpandey
June 20th, 2008, 04:44 AM
Hello all,

The problem is that my session variable dies in another page ...when I link from one page to another. I can access session variable in a.php but a.php -> has a link that takes you to b.php ...now in b.php I can't access that session variable


if(isset($_SESSION['username']))
{
print("What you want if the session var is set");
}
else
{
print("What you want if the sessions variable is not set");
}


It says username is not set ...

whereas I can access and has the correct value in a.php

Please help.

Thanks

PeejAvery
June 20th, 2008, 07:16 AM
Are you sure you are starting the session at the top of every page that is attempting to access the session? Have you used an id or name in one page and not the other?

miteshpandey
June 20th, 2008, 08:23 AM
Yes I am starting the session on each page.

I am using the following as the first line on each page

session_start()


I am not sure I understand what you mean by id or name in one and not other. Could you please explain a bit more?

Thanks

PeejAvery
June 20th, 2008, 08:47 AM
Without supplying a session id or name before creating the session, every person who views your page will have/control the same session.

If you plan to work with logins, you will want something more along the lines of...
session_id('UNIQUE_ID');
session_start();
Or...
session_name('NAME'); // this automatically handles the different ids
session_start();

As to your problem...how about your session configuration in your php.ini file? What is their lifetime? The best way to check would be to use phpinfo() to output your configuration.