I am using the following to lock in a location if a user isn't logged in so that I can return to this location once login is successful
$_SESSION['returnURL'] = htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES);
I am having no luck using this session variable in my header redirect. The contents of this variable currently is: /event.php?title=Test&id=16
if($sql->num_rows==1) {
if (isset($_SESSION['returnURL'])){
$_SESSION['username'] = $username;
header("location:$_SESSION['returnURL'])";
unset($_SESSION['returnURL']);
} else {
$_SESSION['username'] = $username;
header('location:home.php');
}
} else {
die(header("location:login.php?login-failed=true&reason=not_found"));
}
When I replace the contents of $_SESSION['returnURL'] with the address that is stored in $_SESSION['returnURL'] it works perfectly. Something is presenting a problem when I use $_SESSION['returnURL'] variable with header I think.
headerline.header("location:$_SESSION['returnURL'])";you're missing a closing)for the header function. I didn't post an answer because it might just be a typo. Also the answer below addresses your problem.