Block or Redirect bad user agents ot bots via PHP
I found this method on stack overflow which works very good
$badAgents = array('fooAgent','blahAgent', 'etcAgent');
if(in_array($_SERVER['HTTP_USER_AGENT'],$badAgents)) {
exit();
}
BUT
the problem is that the string needs to be perfectly match to the string
inside the array.
I need to came with a new method that will ask if the user agent contains
(in any part of the string) one of the strings inside the array (not
exactly match just ask if it contains ONE of the characters/words inside
several options inside the array)... so I came up with this :
$badAgents = array('google','libwww');
if (strpos(in_array(strtolower($_SERVER['HTTP_USER_AGENT']))), $badAgents)
== true) {
exit();
}
It's not working but I assume this it will work with small tweak.
Thanks a lot in advance guys!
No comments:
Post a Comment