Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect the site a user came from before mine in PHP?

How can I detect the site the user came from before accessing mine in PHP?

like image 202
Viktor Onozo Avatar asked Feb 22 '10 20:02

Viktor Onozo


1 Answers

You could check at the Referer HTTP Header :

echo $_SERVER['HTTP_REFERER'];


But note that the Referer is sent by the browser, which means :

  • It can be disabled (it's not mandatory, and is just an additionnal information that the browser can send)
  • It can be faked (i.e. anyone can send anything -- even some SQL injection, or XSS injection, for instance)


So, you can use the referer to provide an additional feature on your website, but you have to make sure that your website doesn't rely on it : your application must still work, even if the Referer is not present.

like image 175
Pascal MARTIN Avatar answered Sep 30 '22 19:09

Pascal MARTIN