arrays - Block or Redirect bad user agents ot bots via PHP -


i found method on stack overflow works

$badagents = array('fooagent','blahagent', 'etcagent'); if(in_array($_server['http_user_agent'],$badagents)) {     exit(); } 

but

the problem string needs match string inside array.

i need came new method ask if user agent contains (in part of string) 1 of strings inside array (not match ask if contains 1 of characters/words inside several options inside array)... came :

$badagents = array('google','libwww');  if (strpos(in_array(strtolower($_server['http_user_agent']))), $badagents) == true) {     exit(); } 

it's not working assume work small tweak.

thanks lot in advance guys!

in general, best practice use feature detection rather user agent switching.

however, in case, seems parentheses placement off. also, rewrote equality make more clear (since some values may evaluate false).

if (strpos(in_array(strtolower($_server['http_user_agent'])), $badagents) !== false) {     exit(); } 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -