0

Page is not redirecting to the login screen when session value not set. I have echo the value and checked. Session value not exists, even then page not redirecting following is my code.

if(!isset($_SESSION['user']))
{
    header("Location: index.php");
}

2 Answers2

0

I do this slightly differently. Here is a snippet I use. I try to stay away from !isset when I can use the empty instead.

if (empty($_SESSION["user"])){
    header("location: ./index.php");
}
mando222
  • 543
  • 3
  • 6
  • 16
0

You can do like mando222 said, using dynamic URL. Better practice is to set the full URL to the header. Optionally show us your project folders so we can see where you are and where you'd like to go.

Use var_dump($_SESSION); can help us to.

giorgio
  • 10,111
  • 2
  • 28
  • 41