Reputation: 35
I tried to check if the session is still exist, if it doesnt, it will kick me out from the page.
session_start();
if (empty($_SESSION['locationed']))
{
header("Location: http://exit.php");
die();
}
The code above always kick me out of the page.
When I delete the code above and echo the session:
$locationed=$_SESSION['locationed'];
<?php echo $locationed; ?>
It echos my session of location.
What is wrong? Help please.
Upvotes: 0
Views: 85
Reputation: 3256
try isset rather than empty.
if (!isset($_SESSION))
{
header("Location: http://exit.php");
die();
}
Upvotes: 2
Reputation:
session_start();
if(!isset($_SESSION["locationed"]) || empty($_SESSION['locationed']))
{
header("Location: http://exit.php");
die();
}
Upvotes: 1
Reputation: 290
session_start();
$_SESSION['locationed']="1234";
echo $_SESSION['locationed']; //if echo something means getting something on that
if($_SESSION['locationed'] =='' && !isset($_SESSION['locationed']))
{
header("Location: http://exit.php");
die();
}
Upvotes: 1
Reputation: 12391
Here you go .
if (!isset($_SESSION['locationed'])) {
header("Location: http://exit.php");
die();
}
Upvotes: 2
Reputation: 2051
Try those combinations,
if (!isset($_SESSION['locationed']) && empty($_SESSION['locationed'])) {
...
}
Upvotes: 1