本文介绍了奇怪的会话行为 - 会话消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 PHP 和 session 时遇到了非常奇怪的行为.

I am experiencing a very weird behavior with PHP and session.

我正在使用的脚本已经运行了几个月,并且它可以在具有各种 PHP 版本的各种服务器上运行.

The script that I am using has been working for months and it is working on various servers with various PHP versions.

脚本读取 URL 并根据 URL 重新路由,例如点击/offer/abc1234.html 它将调用类 offer 并将 abc1234 作为参数传递.

the script read the URL and re-route depending on the URL, for example hitting /offer/abc1234.html it will call the class offer and pass abc1234 as parameter.

我创建了一个故障转移"类,换句话说,如果您编写/abc1234.html,它将测试各种数据库条目,如果它找到一个自动包含该类,就像它是通过 URL 调用的那样,只需一点额外的开销,区别在于:

I have created a "failover" class that in other words if you write /abc1234.html it will test various database entries and if it finds one automatically include that class like if it was called by URL with just a bit of extra overhead, the difference is:

  • /offer/abc1234.html :: index.php -> offer.php -> home.php
  • abc1234.html :: index.php -> error.php -> failover.php -> offer.php -> home.php

现在,鉴于这一切都有效并且已经工作了几个月,我的问题是会话.

Now, given that this all works and has been working for months my problem is with sessions.

如果我点击/offer/abc1234.html,我会看到会话集和发送到浏览器的 cookie

if I hit /offer/abc1234.html I see the session set and the cookie sent to the browser

如果我点击/abc1234.html 会话设置正确,没有错误 (E_STRICT+E_ALL),没有警告,没有任何内容,但 cookie 不会发送到浏览器.我什至试图在脚本的末尾打印 $_SESSION,并且会话被填充并且除了标题之外的所有变量都是正确的.

if I hit /abc1234.html the session is set correctly, no errors (E_STRICT+E_ALL), no warning, no nothing, but the cookie is not sent to the browser. I even tried to print the $_SESSION at the end of the script, and the session is populated and all the vars are correct except the headers.

我试图调试它并在不同的地方添加各种 var_dump,但除了 header_list() 从不包含 session_cookie 但它确实包含我手动设置的其他 cookie:

I have tried to debug it and add various var_dump in various places, but nothing is different anywhere except the header_list() never contains the session_cookie but it does contain other cookies that I manually set:

我目前正在打印:

  • session_name()
  • session_id() - 每次刷新时都会发生变化,但在整个页面上保持一致
  • session_get_cookie_params()
  • headers_list() - 这不包含 session_start 应该具有的 set-cookie 标头

输出类似于:

  • string(6) "QSCSID"
  • string(26) "456disv3pl4u2j81dej6h6d717"
  • array(5) { ["lifetime"]=> int(0) ["path"]=> string(1) "/" ["domain"]=> string(0) "" ["secure"]=> bool(false) ["httponly"]=> bool(false) }
  • array(4) { [0]=> string(38) "Expires: Thu, 19 Nov 19 08:52:00 GMT" [1]=> string(77) "Cache-Control: no-store,no-cache, must-revalidate, post-check=0, pre-check=0" [2]=> string(16) "Pragma: no-cache" [3]=> string(68) "Set-Cookie:spi=17468; expires=Sat, 26-Oct-2013 05:02:23 GMT; path=/" }

我再次发疯,因为当天早些时候一切正常,然后我重新启动了 apache,它停止工作.

Again, I am getting crazy as everything was working earlier in the day, then I restarted apache and it stopped working.

我已经检查了服务器,但文件夹未满且可写,并且当我调用 abcd1234.html 时,文件已创建且为空

I have checked the server, and the folder is not full and it is writable and the files get created and are empty when I call abcd1234.html

编辑
在处理它时,我开始直接在服务器上通过ee"(FreeBSD 编辑器)打开文件.直到我打开/保存一个类,没有对文件进行任何更改,我不小心添加了一个空格并将其删除,然后当我退出时,编辑器要求我保存,我说是.

EDIT
while working on it, I start to open the files via "ee" (FreeBSD editor) directly on the server. Nothing happened until I opened/saved a class, no changes were made on the file, I accidentally added a space and removed it, then when I exited the editor asked me to save and I said YES.

PHP 是用 eaccelerator 编译的,我已经删除了缓存文件夹并重新启动了 apache 并看到该文件夹​​自动填充.这样的类(failover.php)是一个简单的 4 个函数,其中每个函数都是一个查询,然后构造调用每个函数一次.

PHP is compiled with eaccelerator, I had already removed the cache folder as well as re-restarted apache and saw the folder autopopulate. Such class (the failover.php) is a simple 4 function where each function is a query, then the construct call each function one at the time.

所以,它似乎有效,但我想知道是否有人经历过这样的事情,他们是否知道问题可能是什么

So, it seems working, but I would like to know if anyone ever experienced something like this and if they knew what the issue might have been

推荐答案

我无法复制它,一旦我在 FreeBSD 上打开文件并用ee"关闭,一切正常.

I haven't been able to replicate it, once I opened the file and closed with "ee" on FreeBSD everything worked .

这篇关于奇怪的会话行为 - 会话消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 21:46