$_SESSION not working PHP
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
Code:
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
Re: $_SESSION not working PHP
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?
Re: $_SESSION not working PHP
Yes I am starting the session on each page.
I am using the following as the first line on each page
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
Re: $_SESSION not working PHP
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...
PHP Code:
session_id('UNIQUE_ID');
session_start();
Or...
PHP Code:
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.