samayo
samayo

Reputation: 16495

session conflict between page requests

Just look at this simple example because after hours of trying, I can't get it to work.

if(!isset($_SESSION['alien'])){
  if(!isset($_SERVER['HTTP_REFERER']) &&
      $_SERVER['HTTP_REFERER'] != 'http://www.alien-planet.com/'){
       echo 'Go AWAY';
  }else{
       $_SESSION['alien'] = 'Yes';
  }

}

the purpose is, if someone is coming from alien-planet.com, to never show the Go AWAY message. That is when he/she lands on the index page. But if that person came from that website, a session $_SESSION['alien'] = 'Yes'; will be initialized, so even if that person refreshes the page, or goes through the site links, he/she won't see the message

the problem first time you visit the page, you don't see the Go AWAY message (meaning it works, since I am coming from alien-planet.com) but, as I go to other pages, still with the same site with session_start() included to all pages, I somehow loose the message, and when I go back to index page again I see the Go AWAY message.

I don't understand what is causing this. there are no session destroy/unset in the pages.

Upvotes: 1

Views: 266

Answers (1)

NiMeDia
NiMeDia

Reputation: 1004

Seems like the session is not the same for all requests. Maybe you don't tell php what the user session is. There are different ways, for example the request param PHPSESSID or session cookies.

Please ensure that you use one of the methods. You can simply test it by print out the current session id for each request:

echo session_id();

Upvotes: 1

Related Questions