tags:

views:

329

answers:

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?

A: 

"/" 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

Col. Shrapnel
Sorry, that doesn't solve the problem.
mitch
@mitch clear yout browser cookie cache and try again
Col. Shrapnel
Did so. Still same problem.
mitch
A: 

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?

Syntax Error
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.
mitch
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.
mitch
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.
mitch
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.
mitch
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?!?!
mitch
That's strange. Unfortunately I don't know what could be causing that. Perhaps you should edit your question and mention that is happening in case someone else would know?
Syntax Error