I have a list of domains I want to use as a ban list. The file for the ban list contains domains like: yahoo.com google.com I want to compare those names in the banlist with $_SERVER['HTTP_REFERER'] and if they exist in both the server variable and the banlist file...set a new variable called $dontadd to = 1. The problem I am having is that the domain I want to check against in $_SERVER['HTTP_REFERER'] may have extra data in it like www.domain.com or worse www.foo.domains.com or even trailing info after the domain. Can you guys help me out to only match a domain that was contained in my ban list? Here is my clumsy code so far. $banlist = "http://$siteurl/banlist"; $domain = $_SERVER['HTTP_REFERER']; $domain = str_replace('http://', '', $domain ); $domain = str_replace('/', '', $domain );$domain = "/^$domain/"; $fcg = file_get_contents($banlist); if (preg_match($domain,$fcg)){ $dontadd ='1'; Code (markup): ...which works but it's not fool proof. any ideas how to make it fool proof or close to it? Thanks in advance!
$parse = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST); $banned = file('banlist.txt'); foreach ($banned as $line) { if (stripos($parse, $line)) $dontadd = 1; } PHP: Try that (untested). It should work well enough unless they come from a site like www.google.com.notbannedsite.com, which is unlikely.
deception: No matter what I try with your code $dontadd is always = to 1 It seems as if it counts a line even when there is none. Any other ideas?
phantom: It should work. I think the file() is not reading in the array properly. As it sometimes does to me. Try to just do an array instead. $parse = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST); $banned = array('site.com','site2.com','site3.com'); $skip = false; /* The way to do it with the in_array thingy if (in_array($parse, $banned)) { $skip = true; } */ foreach ($banned as $line) { if (stripos($parse, $line) !== false) { $skip = true; break; } } PHP: