Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Preg_匹配用户代理未正确返回_Php_Preg Match_User Agent - Fatal编程技术网

Php Preg_匹配用户代理未正确返回

Php Preg_匹配用户代理未正确返回,php,preg-match,user-agent,Php,Preg Match,User Agent,我遇到了一个问题,就是如何根据一系列代理正确检测我的用户代理, 即使这是列出的,并通过preg_匹配运行,无论我尝试什么机器人 为了模仿,我永远也得不到积极的评价。我当前的HTTP_用户_代理是 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) 我的$str变量如下所示 /(abcdatos botlink|ariadne|aspider|atn worldwide|auresys|acme.sp

我遇到了一个问题,就是如何根据一系列代理正确检测我的用户代理, 即使这是列出的,并通过preg_匹配运行,无论我尝试什么机器人 为了模仿,我永远也得不到积极的评价。我当前的HTTP_用户_代理是

Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) 
我的$str变量如下所示

/(abcdatos botlink|ariadne|aspider|atn worldwide|auresys|acme.spider|ahoy!|alkaline|alkalinebot|anthill|arachnophilia|arale|araneo|araybot|architextspider|aretha|ask jeeves|askjeeves|atomz|bspider|backrub|bay spider|bayspider|big brother|bjaaland|blackwidow|bloodhound|borg-bot|botlink|boxseabot|cactvs chemistry spider|cmc|calif|cassandra|checkbot|christcrawler.com|collective|combine system|computingsite robi|conceptbot|confuzzledbot|coolbot|cusco|cyberspyder|cydralspider|diibot|dnabot|dwcp|deweb|desert realm spider|die blinde kuh|dienstspider|digger|digimarc|digital integrity robot|direct hit grabber|download express|dragonbot|eit link verifier robot|elfinbot|esi|esirover|esismartspider|ebiness|emacs-w3|esther|evliya celebi|fdse|fastcrawler|felix ide|fetchrover|fish search|fluid dynamics robot|fouineur|freecrawl|funnelweb|gcreep|geneva|getbot|geturl|getterrobo-plus|getterroboplus puu|golem|googlebot|grapnel|griffon|gromit|gulliver|gulper|hi (html index) search|hku www octopus|htmlgobble|hambot|harvest|hometown spider pro|hulud|hyper-decontextualizer|hämähäkki|i, robot|ibm_planetwide|ingrid|ilse|imagelock|incywincy|infoseek robot 1.0|infospiders|informant|infoseek sidewinder|ingrid|inktomi slurp|inspector web|intelliagent|internet cruiser robot|internet shinchakubin|iron33|israeli-search|jbot|jbot java web robot|jcrawler|javabee|jeeves|jobo|jobo java web robot|jobot|joebot|jumpstation|kdd-explorer|kit-fireball|ko_yappo_robot|katipo|kilroy|lwp|labelgrab|labelgrabber|link validator|linkscan|linkscan server|linkscan workstation|linkwalker|linkidator|lockon|lycos|momspider|msnbot|msnbot|mac wwwworm|magpie|mattie|mediafox|merzscope|mindcrawler|monster|motor|mozilla 3.01 pbwf|mozilla|muncher|muninn|muscat ferret|muscatferret|mwd.search|mwdsearch|ndspider|nec-meshexplorer|nhse web forager|nederland.zoek|netcarta webmap engine|netmechanic|netscoop|nomad|northern light gulliver|objectssearch|occam|ontospider|open text index robot|openfind data gatherer|orb search|orbsearch|pgp key agent|pack rat|packrat|pageboy|parasite|patric|perlcrawler 1.0|perlcrawler|phantom|phpdig|piltdownman|pimptrain|pimptrain.com's robot|pioneer|plumtreewebaccessor|poppi|popular iconoclast|portal juice spider|portalb spider|portalbspider|portaljuice.com|puu|rbse spider|rhcs|raven|raven search|raven-v2|resume robot|rixbot|road runner: imagescape robot|road runner: the imagescape robot|roadhouse crawling system|robbie|robbie the robot|robocrawl|robocrawl spider|robofox|robofox v2.0|robot francoroute|robozilla|roverbot|rules|sg-scout|slcrawler|safetynet robot|scooter|search-au|search.aus-au.com|searchprocess|senrigan|shagseeker|shagseeker|shai|shai'hulud|sift|simbot|simmany robot ver1.0|site searcher|site valet|sitetech-rover|skymob.com|sleek|slurp|smart spider|snooper|solbot|spanner|speedy spider|spiderbot|spiderman|spiderman 1.0|spiderview(tm)|spiderline crawler|spry wizard robot|suke|sven|sygol|t-h-u-n-d-e-r-s-t-o-n-e|tach black widow|titan|tlspider|tarantula|tcl w3 robot|techbot|templeton|teoma|teomatechnologies|the jubii indexing robot|the nwi robot|the northstar robot|the peregrinator|the python robot|the tkwww robot|the web moose|the web wombat|the webfoot robot|the world wide web worm|titin|ucsd crawl|url check|url spider pro|udmsearch|ukonline|uptimebot|user-agent: mozilla|vwbot|vwbot_k|valkyrie|verticrawl|verticrawlbot|victoria|voyager|w3m2|wwwc|wwwc ver 0.2.5|walhello appie|wallpaper (alias crawlpaper)|web core |webbandit web spider|webbandit|webcatcher|webcopy|weblinker|webmechanic|webmirror|webmoose|webquest|webreaper|webspider|webstolperer|webvac|webwalker|webwatch|webzinger|webinator|weblog monitor|websnarf|wget|whowhere robot|wild ferret web hopper #1, #2, #3|wired digital|xget|xyleme robot|xavatoria|zilla"|awapclient|abcdatos|ahoy|ananzi|anthill|appie|arale|araneo|araybot|ariadne|arks|askjeeves|atn|atomz|auresys|bigbrother|bjaaland|blindekuh|borg-bot|boxseabot|bright.net caching robot|brightnet|bspider|cienciaficcion.net|cienciaficcion.net spider|calif|cassandra|cgireader|christcrawler|churl|cienciaficcion|cmc|combine|confuzzledbot|coolbot|cosmos|crawlpaper|cruiser|cusco|cyberspyder|cydralspider|desert realm|desertrealm|dienstspider|digger|diibot|directhit|dnabot|download_express|downloadexpress|dragonbot|dwcp|e-collector|ebiness|ecollector|elfinbot|esculapio|esther|evliyacelebi|fastcrawler|fetchrover|fido|fireball|fouineur|freecrawl|gammaspider|gammaspider, focusedcrawler|gazz|gcreep|gestalticonoclast|golem|googlebot|grabber|grapnel|griffon|gromit|gulliver|gulper|gulperbot|hambot|havindex|hometown|hotwired|ht:|htdig|html_analyzer|iajabot|iajabot|iconoclast|image.kapsi.net|imagelock|informant|infoseek|infospider|inspectorwww|irobot|javabee|jcrawler|jobo|kapsi|ko_yappo_robot|label-grabber|labelgrabber.txt|larbin|legs|linkidator|linkwalker|logo.gif|logo.gif crawler|logo_gif_crawler|magpie|marvin|mattie|mediafox|mnogosearch software|mnogosearch|moget|mouse.house|msnbot|muncher|muninn|muscatferret|myweb|netmechanic|netscoop|newscan-online|nil|nzexplorer|occam|orb_search|packrat|pageboy|parasite|patric|pegasus|perlcrawler|phpdig|piltdownman|pimptrain|pjspider|poppi|portalb|psbot|raven|rhcs|rixbot|roadrunner|robbie|robi|robocrawl|robofox|robozillaob o|rules|scooter|search-info|search_au|searchprocess|shaihulud|sharp-info-agent|sift|skymob|slurp|smartspider|snooper|solbot|speedy|spider_monkey|spiderbot|spiderline|spiderview|ssearcher|ssearcher100|straight flash!! getterroboplus 1.5|suke|suntek|sven|tach_bw|tarspider|techbot|templeton|the world wide web wanderer|titin|tlspider|topiclink|udmsearch|uptimebot|urlck|us|valkyrie|verticrawl|victoria|vision-search|void-bot|voidbot|voyager|vwbot|w3mir|w@pspider by wap4.com|w@pspider|wallpaper|wapspider|webcatcher|webfetcher|webinator|weblayers|webquest|webreader|webreaper|webs|webspider|webwalk|webwalker|wget|whatuseek winona|whatuseek_winona|whatuseek|whowhere|winona|wired-digital|wired-digital-newsbot|wlm|wlm-1.1|wolp|wwwc|wz101|xget)^$/

它应该(理论上)在我的$STR变量中看到Google BooT,PrimgSub与StrutLoad($JavaServer [HtppU-UsSeriAg]),认为$$匹配和传递头的增量,但似乎从来没有?这是我目前正在使用的代码,也许有人能帮我解释一下

    //looking for this
    $query = 'klat-badge'; 

    //if not found, continue
    if(strpos($content, $query) === false) { 

        //require banlist
        require('botlist.php'); 

        //compact banlist
        $str = strtolower('/(' . implode('|', $list) .')^$/');
        $matches = array();

        //can we find a match in user agent versus banlist?
        $numMatches = preg_match($str, strtolower($_SERVER['HTTP_USER_AGENT']), $matches, 'i');

            if($numMatches > 0 || $_GET['botban'] == 'true') {

                //so tell bots we're broken
                header("Status: 503");
                header($_SERVER["SERVER_PROTOCOL"].' 503 Service Temporarily Unavailable');

                exit;

            }
    }
它不会从用户代理中看到“
Googlebot
”,因为您的列表将其指定为
|Googlebot
,并且您的正则表达式没有
/i
大小写不敏感修饰符

最后的
^$
当然也是错误的


编辑:刚刚注意到,您的
preg\u replace
调用确实有一个
'i'
参数。那不行。flags参数将只接受整数,这些整数用于PHP包装函数,不会传递到PCRE正则表达式库。

还启用
错误报告(E\u ALL)如果某个东西不起作用。同意,当我将其作为循环运行时,它会立即检测到。谢谢你,马里奥。