-
June 20th, 2008, 04:44 AM
#1
$_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
If there is no love sun won't shine
-
June 20th, 2008, 07:16 AM
#2
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?
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
June 20th, 2008, 08:23 AM
#3
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
If there is no love sun won't shine
-
June 20th, 2008, 08:47 AM
#4
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.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|