i want to allow users to see website only if refer is from facebook facebook page or timeline or like that... if refer is direct or from google i want to block him i have these code where is my mistake? <?php $allowed_domains = array('www.facebook.com/','https://www.facebook.com/'); $REFERRER = $_SERVER['HTTP_REFERER']; if ($REFERRER == '') { // works } $domain = substr($REFERRER, strpos($REFERRER, '://')+3); $domain = substr($domain, 0, strpos($domain, '/')); if (!in_array($domain, $allowed_domains)) { exit(header('Location: error.php')); } ?> Code (markup):
Give this a try, I think the problem is the / you left on one of the domains: NOTE: I disabled the redirect for my testing. <?php $allowed_domains = array('www.facebook.com/','https://www.facebook.com/','www.facebook.com'); //$REFERRER = $_SERVER['HTTP_REFERER']; $REFERRER = "https://www.facebook.com/"; if ($REFERRER == '') { echo "No"; } $domain = substr($REFERRER, strpos($REFERRER, '://')+3); $domain = substr($domain, 0, strpos($domain, '/')); if (!in_array($domain, $allowed_domains)) { echo "No"; //exit(header('Location: error.php')); } else { echo "I am allowed"; } ?> Code (markup):
Just have to add that to the list: $allowed_domains = array('www.facebook.com/','https://www.facebook.com/','www.facebook.com','m.facebook.com');