Tuesday, 2 June 2015

PHP: Check Referrer This checks if the referrer is from the site you expect it to be.

<?php
function check_ref($site = 'thiscode4u.blogspot.com')
{
 if (!array_key_exists('HTTP_REFERER', $_SERVER))
  return false;
 
 $parse = parse_url($_SERVER['HTTP_REFERER']);
 $host = $parse['host'];
 $host = str_replace('www.', '', $host);
 
 return ($host == $site);
}
?>

Usage

if (check_ref('etogre.com')) // they came from etogre.com

die('We love you =^_^= !');

else

die('We hate you -_- !');

0 comments:

Post a Comment