I'm trying to have a secure login page, which was working fine, whilst working with XAMPP, but now that i have switched to Docker, i am getting this error:
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
I'm not sure, if there is some settings i need to do on the container itself and i haven't found a solution so far
I get $_POST Data from a form and pass it on to my 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();
}
The above works fine and i come back to my process.php:
if ($login) {
// Login successful
exit(header('Location: /index.php'));
} else {
// Login not successful
exit(header('Location: /error.php?error=1'));
}
and i get successfully redirected to index.php. In my index.php i call the same method again, to make sure i have the correct user and is authorized to view the page:
require_once(dirname($_SERVER['DOCUMENT_ROOT']) . '/inc/autoloader.php');
$user = new cUser();
$user -> sec_session_start();
and now i stumble onto the error. This is the line:
if (ini_set('session.use_only_cookies', 1) === FALSE) {
I'm not sure what can be wrong here, can someone help me please?
ini_set()
before you do anything that sends headers, such assession_start()
orsetcookie()
. – Barmar