我正在尝试创建一个安全的登录页面,当我使用XAMPP时它工作得很好,但是现在切换到Docker后,我遇到了这个错误:
Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /var/www/inc/cUser.php on line 30
我不确定,是否需要在容器本身上进行一些设置,到目前为止我还没有找到解决办法。
我从表单中获取$_POST数据并将其传递给我的process.php:
require_once(dirname($_SERVER['DOCUMENT_ROOT']) . '/inc/autoloader.php');
$user = new cUser();
$user -> sec_session_start();
cUser.php:
protected function sec_session() {
define("SECURE", true);
$session_name = 'sec_session_id';
$secure = SECURE;
$httponly = true;
if (ini_set('session.use_only_cookies', 1) === FALSE) {
//header("Location: /error.php?err=Could not initiate a safe session (ini_set)");
// here i got the same error twice, so i commented it out and used the code below
echo("<script>location.href = /error.php?err=Could not initiate a safe session (ini_set);</script>");
exit();
}
$cookieParams = session_get_cookie_params();
session_set_cookie_params($cookieParams["lifetime"],
$cookieParams["path"],
$cookieParams["domain"],
$secure,
$httponly);
session_name($session_name);
session_start();
session_regenerate_id();
}
以上内容没问题,我回到了我的process.php文件:
if ($login) {
// Login successful
exit(header('Location: /index.php'));
} else {
// Login not successful
exit(header('Location: /error.php?error=1'));
}
我被成功重定向到index.php。在我的index.php文件中,我再次调用同样的方法,以确保我拥有正确的用户并且被授权查看该页面:
require_once(dirname($_SERVER['DOCUMENT_ROOT']) . '/inc/autoloader.php');
$user = new cUser();
$user -> sec_session_start();
现在我遇到了错误。这是问题所在的代码行:
if (ini_set('session.use_only_cookies', 1) === FALSE) {
我不确定这里出了什么问题,有人能帮我吗?
ini_set()
,例如session_start()
或setcookie()
。 - Barmar