I'm creating a PHP
session, username and all, but when I redirect with header(foo.php
), the $_SESSION
variable appears empty, even though before redirecting it appears properly filled when checking with var_dump.
First I create the session:
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $username;
$_SESSION['start'] = time();
$_SESSION['expire'] = $_SESSION['start'] + (5 * 60);
echo "Bienvenido! " . $_SESSION['username'];
header('location:login-success.php');
exit();
On the next page I start session on top of the page, no HTML above, no nothing:
<?php
session_start();
if(!isset($_SESSION['username'])){
echo "nope";
}
?>
The output is always "nope". I've tried on my localhost and on a remote host, several browsers, cookies are enabled. $_SESSION appears empty when checking with var_dump now.