Détecter les Bots sur un site

WRInaute impliqué
Bonjour,

Je souhaiterais reconnaitre sur mon site s'il s'agit d'un humain ou d'un robot.

J'ai fait un script du genre

Code:
$userAgent = getenv('HTTP_USER_AGENT');
if ( !ereg('([bB]ot|[sS]pider|[yY]ahoo|Rambler|Yahoo|AbachoBOT|accoona|ASPSeek|CocoCrawler|
FAST-WebCrawler|Lycos|MSRBOT|Scooter|AltaVista|eStyle|Scrubby|ia_archiver|ai_archiver|WebCrawler|
abacho | Abacho | adibot | Adifco | spiderman | AESOP | albertbot | AlbertBot | fast | All The Web | overture | All The Web | alpavista | Alpavista | mercator | Alta Vista | scooter | Alta Vista | altavista | AltaVista | aranhabot | Amazon.com | amfibi | Amfibi | amibot | Amidalla | anthill | Anthill | antibot | AntiSearch | aquiseeker | Aquiseeker | arks | Arks | ask | Ask | atom | AtomZ | attentio | Attentio | amiga-aweb | AWeb-Amiga | baiduspider | Baidu | msnbot | Bing | bitmagic | BitMagic | biz360 | Biz360 | blekko | Blekko | bnf.fr_bot | BnF | bspider | BSpider | busca | BuscaPique | cassandra | Cassandra | ccbot | CCBot | cityreview | CityReview | clushbot | Clush | comodo | Comodo | lwp-trivial | CPAN | twiceler | Cuill | cydralspider | Cydral | daum | Daum | deepindex | DeepIndex | Dillo | Dillo | pompos | Dir.com | dittospider | Ditto | tagword | DMOZ | dnabot | DNA | domnutch | DomNutch | dotbot | Dot | ecxi | Ecxi | enigmabot | Enigma | speedy | EntireWeb | envolk | Envolk | euripbot | Eurip | arachnoidea | Euroseek | exactseek | Exact Seek | exabot | ExaLead | architextspider | Excite | fastbot | Fast Search | fast-webcrawler | Fast Web Crawler | finebot | FineSearch | freecrawl | FreeCrawl | gaisbot | Gais | geckobot | Gecko | geohasher | GeoHasher | geonabot | Geona | gigabot | GigaBlast | ocelli | GlobalSpec | googlebot | Google | mediapartners | Google AD-Sense | adsbot | Google AD-Words | feedfetcher | Google Feedfetcher | gralon | Graal | heritrix | Heritrix | homerbot | HomerWeb | toutatis | Hoppa | hotbot | HotBot | aitcsrobot | HTML Index Search | almaden | IBM | ichiro | Ichiro | sidewinder | InfoSeek | ultraseek | InfoSeek | inktomi | Inktomi | ia_archiver | Internet Archive | internetseer | InternetSeer | irlbot | IRL-Crawler | isidorus | Isidorus | ixquick | IxQuick | jyxobot | Jyxo | kmccrew | KmcCrew | kumkie | KumKie | larbin | Larbin | legs | Legs | lexibot | LexiBot | spiderguy | Lexis-Nexis | lexxebot | Lexxe | libertyw | LibertyW | linkchecker | LinkChecker | grub | LookSmart | mantraagent | LookSmart | martini | LookSmart | lycos | Lycos | t-rex | Lycos | vachercher | Lycos | wobot | Magellan | magpie | Magpie | mj12bot | Majestic-12 | casper | MaMa | megabot | MegaGlobe | mlbot | MetaDataLabs | sandcrawler | Microsoft | msrbot | Microsoft Research | henrilerobotmirago | Mirago | henrythemiragorobot | Mirago | findwhat | Miva | miva | Miva / FindWhat | msnbot-media | MSN Media | dumrobo | Naver | naverbot | Naver | dloader | Naver | netcraft | NetCraft | netvibes | NetVibes | nomad | Nomad | gulliver | NorthernLight | nutch | Nutch | openbot | OpenFind | openwebspider | OpenWeb | orangebot | Orange | panelbot | PanelBot | patwebbot | PatSearch | peerbot | PeerBot | picosearch | Pico Search | psbot | PicSearch | pipeliner | Pipeline Search | powermarks | Powermarks | purebot | PureBot | sapo | Sapo | sbider | SBIder | imspider | ScanSoft | scoutjet | ScoutJet | scrubby | Scrub the Web | scilla.pl | Scylla | fluffy | Search Hippo | searchspider | SearchSpider | seoengbot | SEO Engine | sightquest | SightQuest | simplepie | SimplePie | asterias | SingingFish | sitespider | Site Spider | sledink | Sledink | sleipnir | Sleipnir | slik | Slider | slysearch | SlySearch | snapbot | Snap.com | snoopy | Snoopy | sogou | Sogou Spider | solomono | Solomono | sosospider | Soso | spiderku | SpiderKU | suchtop-bot | Suchtop-Bot | summify | Summify | swoogle | Swooglebot | sygol | Sygol | synobot | Synomia | szukacz | Szukacz | taco | Taco Bell | teoma | Teoma | directhit | Teoma | tide | Tide | tineye | TinEye | titan | Titan | tovero | Tovero | twengabot | Twenga | ubicrawler | Ubi | underscorebot | UnderScore | utse | Utse | verticrawl | VertiCrawl | voila | Voila | echo | Voila | amiga | Voyager | voyager | Voyager | w3mir | W3Mir | appie | Walhello | wasabot | Wasa | archive.org_bot | Web Archive | root | Web Core | sitewinder | Webwasher | wget | WGet | winona | WhatUseek | surveybot | WhoIs | wikia | Wikia | wikiwix | Wikiwix | willow | Willow | vagabondo | WiseGuys | wisenut | WiseNut | zyborg | WiseNut | yacy | Yacy | yahooseeker | Yahoo! | slurp | Yahoo! | yandex | Yandex | yaub | Yauba | yellspider | Yell | yeti | Yeti | zao | Zao | zealbot | Zeal | zibber | Zibber | zibie | Zibie | zoomspider | Zoom)', $userAgent))
{
// Mon instruction
}

Cependant j'ai visiblement plusieurs bot de chez Google qui ne respecte pas ma détection de l'useragent.

ai je oublié quelque chose ?

Les ip's concernés sont : 66.249.72.50, 66.249.72.115, 66.249.72.12, etc ...
 
WRInaute accro
Pour bien faire il faut UA + IP.
C'est pour quelle finalité ?
(Si c'est pour afficher ou pas du HTML, tu pourrais peut-être te baser sur $_SERVER['HTTP_X_REQUESTED_WITH'] ?)

NB: ereg est déprécié.
 
WRInaute impliqué
Bonjour et merci de ta réponse :)

Je ne connais pas $_SERVER['HTTP_X_REQUESTED_WITH'], je vais regarder

Quant à la finalité, c'est pour une régie de pub internet donc on incrémente les affichages de +1 si c'est un humain car sinon les stats sont faussées :-(
 
WRInaute accro
Donc dans ce cas tu pourrais passer par AJAX / $_SERVER['HTTP_X_REQUESTED_WITH'].

PHP:
<span class="syntaxdefault"><br /></span><span class="syntaxkeyword">function&nbsp;</span><span class="syntaxdefault">isAjax&nbsp;</span><span class="syntaxkeyword">()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;isset(</span><span class="syntaxdefault">$_SERVER</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'HTTP_X_REQUESTED_WITH'</span><span class="syntaxkeyword">])&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&&&nbsp;</span><span class="syntaxdefault">$_SERVER</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'HTTP_X_REQUESTED_WITH'</span><span class="syntaxkeyword">]&nbsp;==&nbsp;</span><span class="syntaxstring">"XMLHttpRequest"</span><span class="syntaxkeyword">)&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span class="syntaxdefault">true</span><span class="syntaxkeyword">;<br />&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span class="syntaxdefault">false</span><span class="syntaxkeyword">;<br />}<br />&nbsp;</span><span class="syntaxdefault"></span>
Source: http://snipplr.com/view/16624/
 
WRInaute accro
HTML:
PHP:
<span class="syntaxdefault"><br /></span><span class="syntaxkeyword"><</span><span class="syntaxdefault">div id</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"publicite"</span><span class="syntaxkeyword">></</span><span class="syntaxdefault">div</span><span class="syntaxkeyword">><br /></span><span class="syntaxdefault"> </span>

jQuery:
PHP:
<span class="syntaxdefault"><br /></span><span class="syntaxkeyword">$(function(){<br />$(</span><span class="syntaxstring">'#publicite'</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">load</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'publicite.php'</span><span class="syntaxkeyword">);<br />});<br />&nbsp;</span><span class="syntaxdefault"></span>
Ainsi les bots ne chargeront pas la publicité.

publicite.php:
PHP:
<span class="syntaxhtml"><br /><span class="syntaxdefault"><?php <br />function isAjax </span><span class="syntaxkeyword">()<br />{<br /></span><span class="syntaxdefault">    if </span><span class="syntaxkeyword">(<br /></span><span class="syntaxdefault">        isset</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$_SERVER</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'HTTP_X_REQUESTED_WITH'</span><span class="syntaxkeyword">])</span><span class="syntaxdefault"> <br />        </span><span class="syntaxkeyword">&&</span><span class="syntaxdefault"> $_SERVER</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'HTTP_X_REQUESTED_WITH'</span><span class="syntaxkeyword">]</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> </span><span class="syntaxstring">"XMLHttpRequest"</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> <br />        return true</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault">    return false</span><span class="syntaxkeyword">;<br />}<br /><br /></span><span class="syntaxdefault">if </span><span class="syntaxkeyword">(</span><span class="syntaxdefault">isAjax</span><span class="syntaxkeyword">())</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{<br /></span><span class="syntaxcomment">//code HTML pour afficher la pub<br /></span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault">else </span><span class="syntaxkeyword">{<br /></span><span class="syntaxdefault">echo </span><span class="syntaxstring">'Rien à voir ici'</span><span class="syntaxkeyword">;<br />}<br /></span><span class="syntaxdefault">?><br /></span></span>
(le test isAjax() est optionnel)

Je vois pas comment mieux expliquer un truc qui me semble simple :mrgreen:
 
WRInaute impliqué
il y en a encore qui passe :-(

IP address: 209.85.228.93
IP country: United States
IP Address state: California
IP Address city: Mountain View
IP postcode: 94043
IP latitude: 37.4192
IP longitude: -122.0574
ISP: Google
Organization: Google
 
WRInaute accro
Tu es sûr que c'est un Google bot ?
Sur publicite.php ?

Avec le test isAjax() aussi ? Google Bot envoie un XMLHTTPRequest ? 8O
 
WRInaute accro
cloacking a dit:
Je sais pas si c'est un bot mais ça vient de chez google :-(
ne pas oublier qu'il y a des surfs classiques en provenance des ip des bot, ne serait-ce que pour les équipes qualités pour vérifier les sites (par exemple pour voir s'il y a du cloaking), ainsi que pour faire un snapshot pour les aperçus de gg, et puis, avec les directives de panda, pour vérifier si un site a trop de pub :wink:
si tu veux juste éviter que les robots n'affichent ta pub, il suffit de la bloquer en robots.txt
 
WRInaute impliqué
Merci de la réponse Leonick mais ça fait quand même beaucoup de visite si elles sont humaines ...

Je ne veux pas empêcher les robots de voir la publicité, ils peuvent la voir pas de souci :)
C'est juste que je ne veux pas que ça incrémente le nombre d'affichage, là est le problème ?

Pour le robot txt je vais voir :)
 
WRInaute accro
cloacking a dit:
C'est juste que je ne veux pas que ça incrémente le nombre d'affichage, là est le problème ?
pourquoi ne pas utiliser DFP ? comme ça ça sera gg qui gérera ça et faire le tri entre vrai internaute et bot, ils savent le faire
 
WRInaute impliqué
tout simplement car on souhaite gérer en internet et que DFP est trop complexe pour les petits clients qui ne viennent pas du monde du net ;-)

Le fait que les moteurs soient comptabilisés ne causent pas trop de problèmes car on vend au clic mais ça fausse le CTR
 
Discussions similaires
Haut