我已经阅读了很多关于 php 安全最佳实践的信息,并且我正在努力在我的 xampp 服务器上使用它们。
我有一个包含我所有的安全、ddos、会话管理的包含,其中有一个名为 sec_session_start 的函数。代码如下,但是当我尝试登录,然后重定向回我的主页时,所有会话数据都消失了。在我的登录过程页面上,在我进行重定向之前,它具有所有正确的会话数据。
在每个标题之后,我都在做“退出;”。我也试过写 session_write_close();
但这似乎不能解决我的问题。
这是功能代码。
function sec_session_start() {
$session_name = 'AnyName'; // Set a custom session name
$secure = false; // Set to true if using https.
$httponly = true; // This stops javascript being able to access the session id.
ini_set('session.use_only_cookies', 1); // Forces sessions to only use cookies.
$cookieParams = session_get_cookie_params(); // Gets current cookies params.
session_set_cookie_params($cookieParams["lifetime"], $cookieParams["path"], $cookieParams["domain"], $secure, $httponly);
session_name($session_name); // Sets the session name to the one set above.
session_start(); // Start the php session
session_regenerate_id(true); // regenerated the session, delete the old one.
}
这个函数在每一页上被调用。
有什么建议么?