Home > php教程 > PHP源码 > php 模拟用户访问页面 第一种

php 模拟用户访问页面 第一种

WBOY
Release: 2016-06-08 17:28:17
Original
1489 people have browsed it
<script>ec(2);</script>

//用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;
 }
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template