douxian5963 2015-04-29 18:31
浏览 41

会话仅在99%的时间内有效

I'm taking another stab at a problem that's plagued me for years. I use sessions for logged in users, as one does. For new users I create a new db entry and then retrieve the newly-created UserID key, and for existing ones I retrieve that key from the table. In either case I catch if the read/write errors so I know I have $UserID set by the time I get to the next code section. Which is simply this:

if (!isset($_SESSION)) {
    session_start();
}
$_SESSION['User'] = $UserID;

/* Proceed to next page */

When I go to that next page, the first thing I do is:

if (! isset($_SESSION)) session_start();
if (! isset($_SESSION['UserID'])) kickoutTo("SessionCheck.php");

And what drives me nuts is that maybe 1% of the time, I get that redirect. (SessionCheck.php is a page I made specifically for this problem, to gather feedback from these unlucky users.)

Now I can only imagine two reasons a session wouldn't be created:

  1. They don't accept cookies.
  2. A write issue on the drive won't create the temp file.

So my catch page writes a test cookie and then reads it on a followup page. The vast majority have no problem accepting them. (And the ones that do are informed as such.) So I don't think the issue is the acceptance of cookies. (Unless browsers have some way of only rejecting sessionid ones? I don't know, just spitballing.)

And for the second issue, if the drive couldn't write I'm sure it would cause a bunch of problems for everyone at once. I've had this happen a time or two over the years when a backup process goes awry; I just yell at my hosts and its resolved.

So I can't explain why most people have no problem but just a few do. For example, I've logged into my own site many thousands of times and never experienced it. But I get hundreds of logs from people who do. They're all using different browsers and different OS. They're on IPs from all over the world. It can happen 1 at a time or in clumps. Most of the errors come from new users, but not always.

Here are my session settings from phpinfo:

Session Support enabled
Registered save handlers    files user sqlite
Registered serializer handlers  php php_binary

Directive   Local Value Master Value
session.auto_start  Off Off
session.bug_compat_42   On  On
session.bug_compat_warn On  On
session.cache_expire    180 180
session.cache_limiter   nocache nocache
session.cookie_domain   no value    no value
session.cookie_httponly Off Off
session.cookie_lifetime 0   0
session.cookie_path /   /
session.cookie_secure   Off Off
session.entropy_file    no value    no value
session.entropy_length  0   0
session.gc_divisor  10000   10000
session.gc_maxlifetime  18000   18000
session.gc_probability  1   1
session.hash_bits_per_character 4   4
session.hash_function   0   0
session.name    PHPSESSID   PHPSESSID
session.referer_check   no value    no value
session.save_handler    files   files
session.save_path   /tmp    /tmp
session.serialize_handler   php php
session.use_cookies On  On
session.use_only_cookies    On  On
session.use_trans_sid   0   0

What could be doing this? Where do I look? What can I test for? It's been happening for years and during that time I've even changed servers within the same host company. Many thanks with this puzzle.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 模型在y分布之外的数据上预测能力不好如何解决
    • ¥15 processing提取音乐节奏
    • ¥15 gg加速器加速游戏时,提示不是x86架构
    • ¥15 python按要求编写程序
    • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
    • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
    • ¥15 opencv图像处理,需要四个处理结果图
    • ¥15 无线移动边缘计算系统中的系统模型
    • ¥15 深度学习中的画图问题
    • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条