I’m trying to do a Session Authentication in an API.
The server is supposed to send a session_token as a cookie to the client.
This is what my code looks like:
// If no session token found or session token is invalid/expired, generate a new one
if (!$userId) {
$session_token = $this->generateSessionToken();
// Store the session token in the repository
$this->storeSessionToken($user['ID_Utilisateur'], $session_token);
$_SESSION['session_token'] = $session_token;
// Set the session token as a cookie
$cookie_success = setcookie('session_token', $session_token, time() + 86400, '/');
if (!$cookie_success) {
echo("Failed to set session token cookie.");
}
// Store the session token in the PHP session
$_SESSION['session_token'] = $session_token;
}
Why testing the request on insomnia, the error “Failed to set session token cookie” and there is no cookies in the response header.
Why is it the case ?