php 模拟用户访问页面 第一种
<?php
//用php curl_init函数
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, "$url");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0
(compatible; MSIE 6.0; Windows NT 5.1; SV1)");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$contents = curl_exec($ch);
curl_close($ch);
//方法用php fsockopen
function ReadPR($link) {
$fp = fsockopen("www.google.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno) ";
exit(1);
} else {
$out = "GET $link HTTP/1.0 ";
$out.= "Host: toolbarqueries.google.com ";
$out.= "User-Agent: Mozilla/4.0 (compatible; GoogleToolbar
2.0.114.9-big; Linux 2.6) ";
$out.= "Connection: Close ";
fwrite($fp, $out);
do {
$line = fgets($fp, 128);
} while ($line !== " ");
$data = fread($fp, 8192);
fclose($fp);
return $data;
}
}永久链接:http://www.phprm.com/code/851c80decaf831030d9cbbaf84a50254.html
转载随意!带上文章地址吧。