why is my $_SESSION data not getting saved by my script?

Problems with the Mac OS X version of XAMPP, questions, comments, and anything related.

why is my $_SESSION data not getting saved by my script?

Postby bitt3n » 15. August 2008 15:30

I have a script that saves session data, and it works fine on a couple of different hosted webservers I've used it on, but I when using my local install of PHP using XAMPP for OS X, the session data does not persist between pages. (I set the session data on one page, and it no longer exists on the next page.) What do I need to change to get the session data to be saved properly?

I am calling session_start() in every script, and I specified the save directory using

$docroot = $_SERVER['DOCUMENT_ROOT'];
$tmpdir = "$docroot/tmp";
session_save_path($tmpdir);

and set full permissions on this directory, and when I run the script, three session files get created in this directory, but still the session data does not persist between pages.

my webhost php.ini (sessions work fine)

php.ini for my local php installation using xampp (sessions not working)

I should also mention that a cookie I create using setcookie() works fine, but the PHPSESSID cookie never appears.
bitt3n
 
Posts: 2
Joined: 15. August 2008 15:18

Postby Wiedmann » 17. August 2008 09:11

You have a small (!) testscript which is not working?
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby bitt3n » 17. August 2008 21:27

Wiedmann wrote:You have a small (!) testscript which is not working?

ha, good advice. I wrote a script that does nothing but set a session variable, and it worked, and so I kept adding more of my code to find the problem.

turns out that years ago I had accidentally tried to extend the lifetime of the cookie session in two different ways, and only the latter was needed.

setcookie('PHPSESSID',$_COOKIE['PHPSESSID'],time()+$timeout100days, '/', 'mysite.com');

session_set_cookie_params($timeout100days, '/', 'mysite.com');

for some reason this did not cause a problem on various LAMP installations but XAMPP didn't like it. Once I deleted the first line, it works fine.

Just for my own edification, it seems like the setcookie() line should replace the real PHPSESSID with a cookie with value PHPSESSID (ie, completely not what is intended). Why did this work before? It seems like it should always kill the session.

Thanks for the suggestion.
bitt3n
 
Posts: 2
Joined: 15. August 2008 15:18


Return to XAMPP for macOS

Who is online

Users browsing this forum: No registered users and 9 guests