Losing SESSION variables

I have done this a hundred times before without issue. But for some reason on the site I am currently working on I set a session variable and it will be there and displayable on the first page but if I go back through another controller for a new page submission, I am losing them. I have session_start(); at the to of all controllers.

I just output session_id() and have 3 different session id’s on 3 different pages. And if I keep navigating between pages, I keep getting different session id’s. If I look at my session.save_path in php.ini I see
session.save_path = "/var/lib/php/session"
If I look in that directory I don’t see any of my session numbers showing up. Any help would be greatly appreciated.

Quick update, I just did the same thing on another site running on the same web server (vhosts) and it works fine and has been working for quite some time. It’s a shared php installation.

Try moving the session_start() to the start of the first script (what’s presumably your index.php file) so that it’s the first thing to happen

Thanks for the input. It turns out I had the session.cookie_domain = “abc.com” set in httpd.conf in an Apache virtual host environment. So once I used the session_name() and session_set_cookie_params() (with the proper domain name) before I call session_start() all now works fine.

Beware that if you pass a $domain to session_set_cookie_params() the session cookie will be valid for your domain and all subdomains! If you want it to be valid for the domain and the domain only (no subdomains), pass '' or null as the $domain.

If you somehow set a cookie for both PHP will get totally confused and mix them up until you’re debugging yourself blind…

I’ve been fighting with this for hours now, so I thought I’d give you a heads up :slight_smile:

Thanks for the input. By subdomains do you mean go.abc.com and new.abc.com as opposed to abc.com/sub1, abc.com/sub2?

However I will try the “” as a value. I believe that is the recommended default in any event.

Thanks for the input, I appreciate it.

Exactly. In that case if you set abc.com as $domain for the cookie it will be valid for go.abc.com and new.abc.com, whereas if you set $domain to '', it is only valid for the current domain (ie, abc.com or www.abc.com depending on which is default) and none of the subdomains.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.