我正在尝试创建一个安全的登录页面,该页面在使用 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) {
我不确定这里有什么问题,有人可以帮助我吗?
catspeake