2

Common problem, but I'm stumped. Session variables are passing across pages on my local (localhost) deployment, but not on my (www) host. I use a common includes file for each page with this code:

$sessionDomain = "/";
@ini_set("session.cookie_path",$sessionDomain);
$sessionName = "ccSID".md5('/store/');
session_name($sessionName);
session_start();

I confirmed that the session ID cookie (ccSIDxxxxx...) remains the same across pages in my browser, but session variables don't seem to hold up when changing to a page in a different directory.

EDIT: My session cookie file has legible data from one path directory, but not another. I noticed that the good directory has a blank php.ini file in it. When I place a blank php.ini file in the bad directory, the session cookie becomes legible but then regular browser cookies don't save from pages in that directory. What's the deal with (blank) php.ini files in directories that change the behaviour of the session cookie?

14
  • Did you check whether the cookie is accepted and sent in subsequent requests? Commented Mar 21, 2010 at 16:47
  • As long as I request pages from the same directory, the (session) cookies stay set. Request from a different directory, cookie is gone. Commented Mar 21, 2010 at 17:10
  • But you said quite contrary in your question - I confirmed that the session ID cookie remains the same across pages . And now you said cookie is gone. Anyway you have to get rid of the all this fun stuff leaving session_start(); only. I am sure you will get your site working. HTTP interchange log would also help in cookie debugging. Commented Mar 21, 2010 at 17:13
  • Sorry, the session_name (browser) cookie remains the same. But (session) cookies (or session variables) (e.g. $_SESSION['test']) do not. Why does this work locally and not on my host? Commented Mar 21, 2010 at 17:18
  • Nobody can tell you except for HTTP sniffer. Run some while you surf your site and watch what exact cookie does server set Commented Mar 21, 2010 at 17:22

2 Answers 2

1

"/" looks like a path, not domain.
Why don't you just leave session settings alone, with default values?
if session cookie goes all right, you have to check files within session.save_path

Sign up to request clarification or add additional context in comments.

Comments

1

I have a sneaking feeling that you're saving cookies in more than one place. Since you're naming them yourself the name might be the same, but it would in effect be a completely different session.

Look on your server at the actual session files. Are they all where they're supposed to be? Are there a bunch showing up where they don't belong?

If this is the case it you're path is probably being set relative rather than absolute even though it doesn't look like it from what you've shown here.

Also, perhaps you should take the shutup operator (@) off of your ini_set() so you can see if it is complaining about anything?

6 Comments

I have since placed my session array by using session.save_path and am now observing that file. Looks fine when saving variables from one page, but weird when saving from another (as if the cookie is encoded). Again, works fine this way on my local.
Session data is being saved where I expect and when I expect, but when testing with a simple variable ($_SESSION['test'] = 'test';), it is unintelligible from one page, but clear from another. It is definitely saving to the same session name and place, but garbled from on page and not from another.
I get (test|s:4:"test";) with the problem page on my local server (is working fine), but I get (iFcXRQdc4KoZBgg2AMi4hKTzR380YphO8xCK4fK6IDPIRrbk7Nnnaq06FlbbH0YmBGzMbMy85TVGXPyDdDI5KMtq08PQMuK6ypGKKyYDowA.) when trying same on my host server.
Just tested again with simple file to set a session variable. Only moved the file from one path directory to another and get the garbled cookie.
Seems to work if I place an empty php.ini file in the directory with the problem, but that causes a problem with setting cookies?!?!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.