yosuga Posted April 22, 2014 Share Posted April 22, 2014 (edited) Hello, i want to blacklist visitors who come from some specific sites, i've hear i can do that from a .htaccess but i want to do that in PHP. I've do this code for the moment but seem my array have a problem with strpos, any idea ? <?php $referer = $_SERVER['HTTP_REFERER']; $badsites = array('google.com', 'example.com', 'examples2.com'); $pos = strpos($referer, $badsites); if ($pos) {header('Location:blocked.php');} ?> Warning: strpos() [function.strpos]: needle is not a string or an integer in /www/index.php on line 4 Regards Edited April 22, 2014 by yosuga Quote Link to comment Share on other sites More sharing options...
yosuga Posted April 22, 2014 Author Share Posted April 22, 2014 oh just for information i solved it like this: <?php function strposa($haystack, $needle, $offset=0) { if(!is_array($needle)) $needle = array($needle); foreach($needle as $query) { if(strpos($haystack, $query, $offset) !== false) return true; // stop on first true result } return false; } $referer = $_SERVER['HTTP_REFERER']; $array = array('google.com', 'example2.com', 'example3.com'); $locka = strposa($referer, $array); if($locka) { header('Location: blocked.php'); } else { //echo 'test'; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.