|
-
Oct 20th, 2005, 03:01 AM
#1
Thread Starter
Member
Problem with $_SESSION
I have a PHP page with an HTML form that checks a users username and password using a MySQL connection, and if they are correct stores them in the $_SESSION cookie. Then the browser is redirected to the home page 'index.php' where the $_SESSION variables are successfully retrieved and the user is shown as logged in.
However, when I move to another PHP page that uses exactly the same code to access $_SESSION, it cannot find the variables. If I go back to 'index.php', and even refresh the page, it still says logged in. Another website I've built (same server, different directory) functions fine using $_SESSION.
What the hell is going on? Cookies are definitely enabled, $_SESSION is definitely being set, all pages have 'session_start();' but I can only get to it from one webpage.
Any help much appreciated - this is doing my head in!!
-
Oct 20th, 2005, 04:09 AM
#2
Re: Problem with $_SESSION
Without seeing your code and your PHP.ini settings, it is hard to know exactly what is causing the problem. But here are a few suggestions you may want to look into:
- Check that you are not overwriting the $_SESSION array or any of the variables in your session which you need.
- In the PHP.ini file, look for the session.savepath setting and change this to a different directory. When you navigate to your page, the session module should create a file which matches the session ID in this directory. Open this file in a text editor such as notepad and chack that it contains the data you expect it to after each page refresh and that the file doesn't get deleted un expectedly.
- The session module by default uses a cookie to keep track of the session ID for each user called PHPSESSID. Check that the cookie exists and check its parameters. I recommend you use Firefox for this as it gives you detailed information about the cookies, like when they expires, which domain they are valid for, which directory etc...
Its worth noting that if the page is located on a different domain or subdomain form the other pages the session module will not be able to read the cookie it. - Lastly, check the cookie parameters for the session module in the PHP.ini file. All the session settings are prefixed with session.* . Make sure that these are correct.
-
Nov 7th, 2005, 01:04 AM
#3
Member
Re: Problem with $_SESSION
probably you forgot
start_session(); on every page that needs session.
-
Nov 7th, 2005, 11:48 AM
#4
Thread Starter
Member
Re: Problem with $_SESSION
 Originally Posted by snappel
Cookies are definitely enabled, $_SESSION is definitely being set, all pages have 'session_start();'
-
Nov 7th, 2005, 11:57 AM
#5
Re: Problem with $_SESSION
Did you try what I suggested?
-
Nov 9th, 2005, 08:52 AM
#6
Thread Starter
Member
Re: Problem with $_SESSION
I tried the bits I could. I can't access PHP.ini because it's locked off (not my webserver). I moved the whole site to a different subdirectory and it worked fine. Strange...
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
|