假设我们有以下perl脚本
use LWP; use strict; use warnings; use LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->agent('NokiaN97i/SymbianOS/9.1 Series60/3.0'); my $response = $ua->get('http://myhost.com'); if ($response->is_success) print $response->decoded_content; else die $response->status_line;
它只是连接到myhost.com/index.PHP页面并打印其内容.
在index.PHP文件中我有
file_put_contents('agent.txt',$_SERVER['HTTP_USER_AGENT'],FILE_APPEND);
线.现在用户代理字符串不包含“libwww-perl”.我如何识别perl bot并限制它?
解决方法
你不能,USER_AGENT字符串虽然是帮助你识别客户端“浏览器”的唯一因素,但基本上也是用户输入.如果他们改变它 – 你无能为力.