Reputation: 153
Here is my code :
$login = $_SESSION['login'];
$statut = $_SESSION['statut'];
$atelier = $_SESSION['atelier'];
$connexion = $_SESSION['connexion'];
session_destroy ();
$_SESSION['login'] = $login;
$_SESSION['statut'] = $statut;
$_SESSION['atelier'] = $atelier;
$_SESSION['connexion'] = true;
header('Location: http://10.13.48.60/no_serie.php');
Soo when I arrive here, the header send me to the correct page but I loose each time my login value like if it didn't save again my $_SESSION value. Am I doing something wrong ?
Or an another solution would be to put the variables in the link like :
header('Location: http://10.13.48.60/no_serie.php?login = '.$login.', statut = '.$statut.', ...');
But I prefer the $_SESSION
solution.
ps : I start each of my page with session_start();
and I never touch to the $_SESSION
value.
Thanks
Upvotes: 0
Views: 993
Reputation: 883
You destroy the complete session but you dont (re)start it.
session_destroy();
session_start();
Upvotes: 1
Reputation: 4063
You called session_destroy()
then set more sessions, so you need to make sure session_start()
is called again before resetting the sessions. Or don't call session_destroy
at all.
Like so:
$login = $_SESSION['login'];
$statut = $_SESSION['statut'];
$atelier = $_SESSION['atelier'];
$connexion = $_SESSION['connexion'];
// session_destroy (); - unnecessary
$_SESSION['login'] = $login;
$_SESSION['statut'] = $statut;
$_SESSION['atelier'] = $atelier;
$_SESSION['connexion'] = true;
header('Location: http://10.13.48.60/no_serie.php');
From PHP.net:
session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie. To use the session variables again, session_start() has to be called.
http://php.net/manual/en/function.session-destroy.php
Upvotes: 5