PHPSESSID not being saved to cookie

15,304

Solution 1

It looks like the cookie's domain is being set to localhost. This will only work if you're actually running your website from localhost. You need the session.cookie_domain to match your domain name, optionally with a . in front of it (as in .example.com) to also include subdomains.

Solution 2

It is not used for Yoav's case, but maybe used for other people who got similar issue:

don't forget to call session_start()

It sounds like session_start() would create the PHPSESSID and save it in cookie if it's not sent from client cookie.

from php.net

When a visitor accesses your site, PHP will check automatically (if session.auto_start is set to 1) or on your request (explicitly through session_start()) whether a specific session id has been sent with the request. If this is the case, the prior saved environment is recreated.

some good examples about session_start() http://php.net/manual/en/function.session-start.php

Share:
15,304
Yoav Kadosh
Author by

Yoav Kadosh

Web Developer B.Sc. in Computer Science and Mathematics CodePen Medium Github Dev.to Projects GradientArt Webrix.js

Updated on June 15, 2022

Comments

  • Yoav Kadosh
    Yoav Kadosh almost 2 years

    the PHPSESSID variable that holds the session id is not being saved into the client cookie. This results in a new session id being generated every time I call the session_start() function.

    This is true when i'm using FireFox, Opera and Chrome. With safari, for some reason, this variable is being successfuly saved into the cookie and everything works fine.

    EDIT: Here is my session settings via phpinfo():

    session settings via phpinfo

    My website has a subdomain, and I want to use the same session acorss all subdomains.

    2nd EDIT: when I check var_dump($_COOKIE); on my main domain I get the session id under the name PHPSESSID but when I do that on the subdomain I get an empty array().

  • Yoav Kadosh
    Yoav Kadosh about 12 years
    You're right, it works fine in my main domain (localhost) but even after setting ini_set('session.cookie_domain', '.localhost' ); im still having an issue with the subdomain (forum.localhost)
  • Trần Hữu Hiền
    Trần Hữu Hiền almost 3 years
    Work in case I deleted session ID by my hand :)