array ( 'HTTP_HOST' => '192.168.30.205', 'PATH' => 'C:/Program Files/Common Files/NetSarang;C:/Program Files/NVIDIA Corporation/PhysX/Common;C:/Program Files/Common Files/Microsoft Shared/Windows Live;C:/Program Files/Intel/iCLS Client/;C:/Windows/system32;C:/Windows;C:/Windows/System32/Wbem;C:/Windows/System32/WindowsPowerShell/v1.0/;C:/Program Files/Intel/Intel(R) Management Engine Components/DAL;C:/Program Files/Intel/Intel(R) Management Engine Components/IPT;C:/Program Files/Intel/OpenCL SDK/2.0/bin/x86;C:/Program Files/Common Files/Thunder Network/KanKan/Codecs;C:/Program Files/QuickTime Alternative/QTSystem;C:/Program Files/Windows Live/Shared;C:/Program Files/QuickTime Alternative/QTSystem/; %JAVA_HOME%/bin;%JAVA_HOME%/jre/bin;', 'SystemRoot' => 'C:/Windows', 'COMSPEC' => 'C:/Windows/system32/cmd.exe', 'PATHEXT' => '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC', 'WINDIR' => 'C:/Windows', 'SERVER_SIGNATURE' => '', 'SERVER_SOFTWARE' => 'Apache/2.2.11 (Win32) PHP/5.2.8', 'SERVER_NAME' => '192.168.30.205', 'SERVER_ADDR' => '192.168.30.205', 'SERVER_PORT' => '80', 'REMOTE_ADDR' => '192.168.30.205', 'DOCUMENT_ROOT' => 'E:/wamp/www', 'SERVER_ADMIN' => '[email protected]', 'SCRIPT_FILENAME' => 'E:/wamp/www/user-agent.php', 'REMOTE_PORT' => '59479', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'SERVER_PROTOCOL' => 'HTTP/1.0', 'REQUEST_METHOD' => 'GET', 'QUERY_STRING' => '', 'REQUEST_URI' => '/user-agent.php', 'SCRIPT_NAME' => '/user-agent.php', 'PHP_SELF' => '/user-agent.php', 'REQUEST_TIME' => 1400747529, )
后来使用CURL来获取,就获取到了网页,不过使用上稍微麻烦一点,首先伪造UA,获取之后在使用正则表达式分析<meta>.
伪造办法,代码如下:
// 初始化一个 cURL $curl = curl_init(); // 设置你需要抓取的URL curl_setopt($curl, CURLOPT_URL, 'http://localhost/user-agent.php'); // 设置是否将文件头输出到浏览器,0不输出 curl_setopt($curl, CURLOPT_HEADER, 0); // 设置UA,这里是将浏览器的UA转发到服务器,也可以手动指定值 curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 设置cURL 参数,要求结果返回到字符串中还是输出到屏幕上。0输出屏幕并返回操作结果的BOOL值,1返回字符串 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 运行cURL,请求网页 $data = curl_exec($curl); // 关闭URL请求 curl_close($curl); // 处理获得的数据 var_dump($data);
希望本文所述对大家的PHP程序设计有所帮助。