Hardbyte Posted July 5, 2006 Share Posted July 5, 2006 Hi-ya.To start with, Iv got the below code:-[code]$agent = strtoupper($_SERVER['HTTP_USER_AGENT']);$bots = array('GOOGLE','GOOGLEBOT','BOT');if (in_array($agent, $bots)){ // do something here.}else{// do something else here.}[/code]I assume the above code is stating: if $agent == $bots (equal to BOT). But how do I make it so its *like* BOT, incase its really [b]BOT[/b]S or STUPID[b]BOT[/b]S ?Iv been playing around with strstr but it dont seem to work in this array style (unless Im doing it wrong).Any help would be appreciated.Thanks Quote Link to comment https://forums.phpfreaks.com/topic/13719-in_array-strstr-bots/ Share on other sites More sharing options...
Orio Posted July 5, 2006 Share Posted July 5, 2006 [code=php:0]$agent = strtoupper($_SERVER['HTTP_USER_AGENT']);$bots = array('GOOGLE','GOOGLEBOT','BOT');$continue=0;foreach($bots as $bot){if(strstr($bot,$agent)!==FALSE){$continue=1;};};if(continue==1){// do something here.}else{// do something else here.};[/code][hr]Hope it helps :)Orio. Quote Link to comment https://forums.phpfreaks.com/topic/13719-in_array-strstr-bots/#findComment-53271 Share on other sites More sharing options...
Hardbyte Posted July 5, 2006 Author Share Posted July 5, 2006 Hi-ya, thanks for the reply.Im afraid its still not working. Below is your new code implemented:-[code]$agent = strtoupper($_SERVER['HTTP_USER_AGENT']);$bots = array('GOOGLE','GOOGLEBOT','BOT','CRAWLER');$continue=0;foreach($bots as $bot){if(strstr($bot,$agent)!==FALSE){$continue=1;};};if($continue==1){ //send mail (of bot array)$subject = "Reported Bot";$headers = "From: email@addy.com>"; $message = $agent." has visited ".$_SERVER['REQUEST_URI']."\n\nArray Bot ";mail("myemailaddy@domain.com", $subject, $message, $headers);}else{//send mail (all)$subject = "Reported Bot";$headers = "From: <email@addy.com>"; $message = $agent." has visited ".$_SERVER['REQUEST_URI']."\n\nArray Bot: not in array ";mail("myemailaddy@domain.com", $subject, $message, $headers); };[/code]Im trying to determine which bots from my array are going to the site, it then emails me if it was a bot in my array or something else (like IE or Firefox) picking up on keywords such as BOT in GOOGLE[b]BOT[/b], [b]BOT[/b]S, BOTa[b]CRAWLER[/b] etc..Many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/13719-in_array-strstr-bots/#findComment-53285 Share on other sites More sharing options...
Orio Posted July 5, 2006 Share Posted July 5, 2006 I am not sure if you mean to check (for example) if "GOOGLE" is inside $agent, or vice cersa- $agent is in "GOOGLE".If it's "GOOGLE" inside $agent, this is how it's supposed to be:if(strstr($agent,$bot)!==FALSE){$continue=1;};(I changed $bot,$agent to $agent,$bot).Orio. Quote Link to comment https://forums.phpfreaks.com/topic/13719-in_array-strstr-bots/#findComment-53289 Share on other sites More sharing options...
Hardbyte Posted July 5, 2006 Author Share Posted July 5, 2006 Hi-ya,I also just did the same but you replied before I got here ;DI changed:[code]if(strpos($agent,$bot)!==FALSE){$continue=1;};[/code]Just waiting to be crawled lolMany Thanks Quote Link to comment https://forums.phpfreaks.com/topic/13719-in_array-strstr-bots/#findComment-53291 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.