yosuga Posted April 22, 2014 Share Posted April 22, 2014 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 Link to comment https://forums.phpfreaks.com/topic/287947-blacklisting-referers-with-php/ 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'; } ?> Link to comment https://forums.phpfreaks.com/topic/287947-blacklisting-referers-with-php/#findComment-1476997 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.