国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 語(yǔ)言 > PHP > 正文

php使用fsockopen函數(shù)發(fā)送post,get請(qǐng)求獲取網(wǎng)頁(yè)內(nèi)容的方法

2024-09-04 11:43:08
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

這篇文章主要介紹了php使用fsockopen函數(shù)發(fā)送post,get請(qǐng)求獲取網(wǎng)頁(yè)內(nèi)容的方法,是PHP關(guān)于socket編程的一個(gè)典型應(yīng)用,需要的朋友可以參考下

本文實(shí)例講述了php使用fsockopen函數(shù)發(fā)送post,get請(qǐng)求獲取網(wǎng)頁(yè)內(nèi)容的方法。分享給大家供大家參考。

具體實(shí)現(xiàn)代碼如下:

  1. $post =1; 
  2. $url = parse_url($url); 
  3. $host ='http://www.survivalescaperooms.com'
  4. $path ='/'
  5. $query ='?action=Vevb.com'
  6. $port =80; 
  7.  
  8. if($post) { 
  9.   $out = "post $path http/1.0 "
  10.   $out .= "accept: */* "
  11.   //$out .= "referer: $boardurl "; 
  12.   $out .= "accept-language: zh-cn "
  13.   $out .= "content-type: application/x-www-form-urlencoded "
  14.   $out .= "user-agent: $_server[http_user_agent] "
  15.   $out .= "host: $host "
  16.   $out .= 'content-length: '.strlen($post)." "
  17.   $out .= "connection: close "
  18.   $out .= "cache-control: no-cache "
  19.   $out .= "cookie: $cookie "
  20.   $out .= $post
  21.  } else { 
  22.   $out = "get $path http/1.0 "
  23.   $out .= "accept: */* "
  24.   //$out .= "referer: $boardurl "; 
  25.   $out .= "accept-language: zh-cn "
  26.   $out .= "user-agent: $_server[http_user_agent] "
  27.   $out .= "host: $host "
  28.   $out .= "connection: close "
  29.   $out .= "cookie: $cookie "
  30.  } 
  31.  $fp = @fsockopen(($ip ? $ip : $host), $port$errno$errstr$timeout); 
  32.  if(!$fp)  
  33.  { 
  34.   return '';//note $errstr : $errno  
  35.  } else { 
  36.   return '成功訪問(wèn)'
  37.  } 

fsockopen語(yǔ)法:

resource fsockopen(string $hostname [,int $port = -1 [, int &$errno [,string &$errstr [, float $timeout = ini_get("default_socket_timeout") ]]]] )

啟動(dòng)一個(gè)套接字連接到指定的主機(jī)的資源,php支持在互聯(lián)網(wǎng)領(lǐng)域的目標(biāo)和unix在所支持的套接字傳輸列表說(shuō)明,所支持的傳輸列表也可以檢索使用stream_get_transports().

該插座預(yù)設(shè)會(huì)被啟用,阻塞模式,你可以切換到非阻塞模式使用stream_set_blocking(),如果上面實(shí)例看不懂,就來(lái)看個(gè)簡(jiǎn)的吧,代碼如下:

  1. $fp = fsockopen("www.survivalescaperooms.com", 80, $errno$errstr, 30); 
  2.  if (!$fp) { 
  3.   echo "$errstr ($errno) "
  4.  } else { 
  5.   $out = "get / http/1.1 "
  6.   $out .= "host: www.survivalescaperooms.com"
  7.   $out .= "connection: close "
  8.   fwrite($fp$out); 
  9.   while (!feof($fp)) { 
  10.    echo fgets($fp, 128); 
  11.   } 
  12.   fclose($fp); 
  13.  } 

希望本文所述對(duì)大家的PHP程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 铁力市| 长乐市| 红河县| 南汇区| 达拉特旗| 钟山县| 新化县| 通海县| 平邑县| 巴马| 乾安县| 乐业县| 丹凤县| 五家渠市| 伊金霍洛旗| 克拉玛依市| 会昌县| 齐河县| 三原县| 普定县| 新乡市| 南江县| 铁岭县| 重庆市| 兰考县| 临夏县| 林西县| 鄢陵县| 沙坪坝区| 万山特区| 宜昌市| 福鼎市| 晋州市| 五原县| 五寨县| 芦山县| 庆城县| 丹东市| 长垣县| 建湖县| 建始县|