Questa funzione mi scrive su un file quando passano i vari spider:
if (strstr($_SERVER['HTTP_USER_AGENT'], 'Googlebot')){$bot='Googlebot';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'Mediapartners')){$bot='Adsense';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'Slurp')){$bot='Hot Bot';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'ichiro')){$bot='ichiro';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'msnbot')){$str_bot='Msn';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'bingBot')){$str_bot='Bing';}
Funziona, ma non con tutti i bot.
Per esempio, dal log del server vedo che è passato "bingbot" ma la funzione non scrive nulla.
Invece scrive quando passa Googlebot, ichiro....
Potrei ipotizzare che succeda perchè utilizzi la funzione strstr che è case-sensitive mentre ti consiglio di utilizzare la stristr che non è case-sensitive.
Se bing arriva come bingbot allora strstr(USER_AGENT, bingBot) = false mentre se arriva come bingBot allora strstr(USER_AGENT, bingBot) = true.
Per la stristr bingBot e bingbot sono la stessa cosa quindi stristr(USER_AGENT, bingBot) = true e stristr(USERAGENT, bingbot) = true.
Prova a sostituirla, dovresti aver risolto il problema...
Premesso che cambiaero la funzione con quella suggerita da te che non conoscevo, io sono stabe ben attento al case, poichè rilevo il testo esatto dal log accessi del mio server.
e mi falliscono tutti questi test sulla stringa:
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'leipzig')){$bot='lp1';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'links')){$bot='lp2l';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'worts')){$bot='lp3';}
Ci sarà da qualche parte una stupidata che non riesco a vedere... :(
PS
in ogni caso un errore l'ho gia trovato: la variabile dove metto il risultato una volta è $str_bot e una volta è $bot.
messo a posto, ma il problema con quel bot (e altri) rimane
Ultima modifica di netgreg : 11-08-2012 alle ore 12.25.13