I have a site that is working in localhost, but when I moved to another server, I’m facing some issues trying to recover the date that I keep in the $_SESSION.
I’ve read a lot about this, and I tryied trying to manage the SameSite configuration.
$secure = true;
$httponly = true;
$samesite = 'None';
$maxlifetime = 50000;
if(PHP_VERSION_ID < 70300) {
session_set_cookie_params($maxlifetime, '/; samesite='.$samesite, $_SERVER['HTTP_HOST'], $secure, $httponly);
} else {
session_set_cookie_params([
'lifetime' => $maxlifetime,
'path' => '/',
'domain' => $_SERVER['HTTP_HOST'],
'secure' => $secure,
'httponly' => $httponly,
'samesite' => $samesite
]);
}
But it doesn’t work. When I try to get any value from $_SESSION… nothing works!!
I’ve also added code like:
header('Access-Control-Allow-Origin: https://myserver.com');
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method');
header('Access-Control-Allow-Methods: GET, POST');
header('Allow: GET, POST, OPTIONS, PUT, DELETE');
… but it doesn’t work either.
I don't know what else to try... so any help is more than welcome!!
Thanks in advance.
$secure = true;
$httponly = true;
$samesite = 'None';
$maxlifetime = 50000;
if(PHP_VERSION_ID < 70300) {
session_set_cookie_params($maxlifetime, '/; samesite='.$samesite, $_SERVER['HTTP_HOST'], $secure, $httponly);
} else {
session_set_cookie_params([
'lifetime' => $maxlifetime,
'path' => '/',
'domain' => $_SERVER['HTTP_HOST'],
'secure' => $secure,
'httponly' => $httponly,
'samesite' => $samesite
]);
}
header('Access-Control-Allow-Origin: https://myserver.com');
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method');
header('Access-Control-Allow-Methods: GET, POST');
header('Allow: GET, POST, OPTIONS, PUT, DELETE');
Firmo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.