Al Kasih
Al Kasih

Reputation: 35

Session is saved but the page kick me out

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

Answers (6)

Roger
Roger

Reputation: 3256

try isset rather than empty.

if (!isset($_SESSION))
    {
         header("Location: http://exit.php");
         die();
    }

Upvotes: 2

user3522371
user3522371

Reputation:

session_start();
if(!isset($_SESSION["locationed"]) || empty($_SESSION['locationed']))
{
  header("Location: http://exit.php");
  die();
}

Upvotes: 1

Mahendra Pumbhadiya
Mahendra Pumbhadiya

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

Danyal Sandeelo
Danyal Sandeelo

Reputation: 12391

Here you go .

if (!isset($_SESSION['locationed'])) {
     header("Location: http://exit.php");
     die();
}

Upvotes: 2

Sudip
Sudip

Reputation: 2051

Try those combinations,

if (!isset($_SESSION['locationed']) && empty($_SESSION['locationed'])) {
...
}

Upvotes: 1

Sagar Koshti
Sagar Koshti

Reputation: 428

try:

if (isset($_SESSION['locationed']))

Upvotes: 1

Related Questions