PHP Session Id changes between pages

前端 未结 10 1995
长发绾君心
长发绾君心 2020-12-07 01:07

I have a problem where i am losing the PHP session between 2 pages.

The session_start() is included in a file called session-inc.php into every page requiring a sess

10条回答
  •  -上瘾入骨i
    2020-12-07 01:44

    I had this problem, and the cause was that PHP was ignoring all cookies after the first 100. (I asked this question to try to find out why, but so far nobody has figured it out). The browser was sending the PHPSESSID*, but since it was the 110th cookie, PHP was ignoring it.

    To figure out if this problem is what's affecting you, use your browser's dev tools to look at the cookies that the browser is sending with the request, and compare that list to the $_COOKIE array in PHP. They should be the same. But if the browser is sending a PHPSESSID*, and there's no PHPSESSID* in $_COOKIE, then that would explain why sessions aren't working.

    I solved the problem by not having my site use so many cookies, which is good practice anyway.

    *PHPSESSID is the default session name. Your site may use a different name.

提交回复
热议问题