code_junkie

Inspect the referrer in PHP

Nov 13th, 2011
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. $referringSite = $_SERVER['HTTP_REFERER']; // is that spelt wrong in PHP ?
  2.  
  3. $referrerIsValid = false;
  4. $hasReferrer = false;
  5. if (isset($_SERVER['HTTP_REFERER'])) {
  6. $parts = parse_url($_SERVER['HTTP_REFERER']);
  7. if (isset($parts['host'])) {
  8. $hasReferrer = true;
  9. $referrerIsValid = (bool) preg_match('/(?:^|.)example.com$/', strtolower($parts['host']));
  10. }
  11. }
Add Comment
Please, Sign In to add comment