|
方法1: 用file_get_contents 以get方式獲取內容:
<?php$url='http://www.jb51.NET/';$html = file_get_contents($url);echo $html;?>
方法2: 用fopen打開url, 以get方式獲取內容:
<?php$fp = fopen($url, ‘r');stream_get_meta_data($fp);while(!feof($fp)) {$result .= fgets($fp, 1024);}echo “url body: $result”;fclose($fp);?>
方法3:用file_get_contents函數,以post方式獲取url
<?php$data = array (‘foo' => ‘bar');$data = http_build_query($data);$opts = array (‘http' => array (‘method' => ‘POST',‘header'=> “Content-type: application/x-www-form-urlencodedrn” .“Content-Length: ” . strlen($data) . “rn”,‘content' => $data));$context = stream_context_create($opts);$html = file_get_contents(‘http://localhost/e/admin/test.html', false, $context);echo $html;?>
方法4:用fsockopen函數打開url,以get方式獲取完整的數據,包括header和body,fsockopen需要 php.ini 中 allow_url_fopen 選項開啟
<?phpfunction get_url ($url,$cookie=false){$url = parse_url($url);$query = $url[path].”?”.$url[query];echo “Query:”.$query;$fp = fsockopen( $url[host], $url[port]?$url[port]:80 , $errno, $errstr, 30);if (!$fp) {return false;} else {$request = “GET $query HTTP/1.1rn”;$request .= “Host: $url[host]rn”;$request .= “Connection: Closern”;if($cookie) $request.=”Cookie: $cookien”;$request.=”rn”;fwrite($fp,$request);while(!@feof($fp)) {$result .= @fgets($fp, 1024);}fclose($fp);return $result;}}//獲取url的html部分,去掉headerfunction GetUrlHTML($url,$cookie=false){$rowdata = get_url($url,$cookie);if($rowdata){$body= stristr($rowdata,”rnrn”);$body=substr($body,4,strlen($body));return $body;}return false;}?>
方法5:用fsockopen函數打開url,以POST方式獲取完整的數據,包括header和body
<?phpfunction HTTP_Post($URL,$data,$cookie, $referrer=”"){// parsing the given URL$URL_Info=parse_url($URL);// Building referrerif($referrer==”") // if not given use this script as referrer$referrer=”111″;// making string from $dataforeach($data as $key=>$value)$values[]=”$key=”.urlencode($value);$data_string=implode(“&”,$values);// Find out which port is needed 主站蜘蛛池模板: 任港秀| 电影终结者| 朱莉与朱莉娅| 挨打的作文| xxxxxxxxxxxx| 动漫头像男| 纽约巨人| 日本电影致命诱惑| 林黛玉进贾府人物形象分析 | 奇妙的植物世界阅读短文答案| 男国少年梦 电影| 忏悔三昧念3遍| 郎雄| 搬山道人| 布里奇顿第四季| 意外的春天 电影| av午夜| 《重紫》电视剧| 触底反弹电影| 电影在线观看网址| 亚洲成a人片在线观看| 碟仙诡谭| 87版七仙女台湾| 减肥蔬菜| 电影《七天》| 任港秀| 一年级下册语文期末测试卷可打印 | 意外的春天| 世界赠予我的钢琴曲| 情欲视频| 猛鬼追魂| 药品管理法试题| 赛虎| 向东海| 心理健康《微笑的力量》ppt| 夜色斗僵尸| 1905电影网| 醉翁亭记理解性默写及答案| angelina全集在线观看| 热带夜的引诱| 青春之放纵作文免费阅读|