【发布时间】:2016-07-02 17:17:27
【问题描述】:
我目前正在为一个客户开发一个网络应用程序,该客户的网络空间托管在 one.com 上。
我已经实现了自己的安全登录系统,一切正常。当我登录某人时,这些变量是可用的,但是一旦我通过 href 转到新页面,我的所有会话变量都会丢失。我已经尝试了几乎所有在类似问题上推荐的东西,但它不起作用。
我不能直接编辑我的php.ini,这是标准的phpinfo:
I can't embed Images yet, this is my phpinfo
另外在我调用的每个站点的开头
ini_set("session.cookie_secure", 0);
因为一开始这(本地)总是设置为 true。
我使用以下代码在每个页面上启动安全会话:
$session_name = 'sec_session_id'; // Set a custom session name
$secure = true;
// This stops JavaScript being able to access the session$id.
$httponly = true;
// Forces sessions to only use cookies.
if (ini_set('session.use_only_cookies', 1) === FALSE) {
header("Location: ../error.php?err=Could not initiate a safe session (ini_set)");
exit();
}
// Gets current cookies params.
$cookieParams = session_get_cookie_params();
session_set_cookie_params($cookieParams["lifetime"],
$cookieParams["path"],
$cookieParams["domain"],
$secure,
$httponly);
// Sets the session name to the one set above.
session_name($session_name);
session_start(); // Start the PHP session
session_regenerate_id(true); // regenerated the session, delete the old one.
我只是不明白为什么我的 Session 变量总是丢失。我会很高兴能得到每一个帮助!
编辑:有人建议最后一行:
session_regenerate_id(true);
可能会导致问题,但删除后仍然无法正常工作。还能是什么?
【问题讨论】:
-
嗯……
session_regenerate_id(true); // regenerated the session, delete the old one.……你说你的会话数据每次都会被删除? -
我认为这个调用只会删除旧的、易受攻击的变量。不是这样吗?
-
会话cookie是否安全地从服务器接收并发回?
-
我该如何检查这个?