您的位置:首页 > Web前端

[乐意黎]php curl 以及refer设置

2016-06-12 11:27 267 查看
echo
"<pre>"
;print_r(
$info
);
die
(
$output
);
PHP code?
得到的数据中有<title>T浦力顿500g 成犬幼犬狗粮泰迪贵宾比熊金毛萨摩耶博美 批发散装-淘宝网</title><h3 class="tb-item-title">T浦力顿500g 成犬幼犬狗粮泰迪贵宾比熊金毛萨摩耶博美 批发散装</h3>证明访问是没有问题的PHP code?
referer是php用来判断页面上级来源页面的一个超级变局变量了,我们可以使用referer来判断是从那个页面进入到此页面了,这样我们可以进行更好的跟踪了,下面我就来给各位朋友整理了几种伪造页面referer来源例子,希望例子能给各位朋友。file_get_contents方法
代码如下
$opt=array('http'=>array('header'=>"Referer: $refer"));$context=stream_context_create($opt);$file_contents = file_get_contents($url,false, $context);
分析:
file_get_contents中stream_context_create就伪造来源的重要参数了,这个什么好说的非常的简单。
CURL方式
代码如下
$ch = curl_init();curl_setopt ($ch, CURLOPT_URL, "http://www.111cn.net");curl_setopt ($ch, CURLOPT_REFERER, "http://www.111cn.net/");curl_exec ($ch);curl_close ($ch);
分析:
curl伪造来源页面非常的简单这是它的优点了,所以我们只要在页面加上curl_setopt ($ch, CURLOPT_REFERER, "http://www.111cn.net/");就可以了。
SOCKET方式
代码如下
$server = 'www.111cn.net';$host = 'www.111cn.net';$target = 'index.php';$referer = 'http://www.111cn.net/'; // Referer$port = 80;$fp = fsockopen($server, $port, $errno, $errstr, 30);if (!$fp){echo "$errstr ($errno)\n";}else{$out = "GET $target HTTP/1.1\r\n";$out .= "Host: $host\r\n";$out .= "Referer: $referer\r\n";$out .= "Connection: Close\r\n\r\n";fwrite($fp, $out);while (!feof($fp)){echo fgets($fp, 128);}fclose($fp);}
友情提示:三种性能比对fsockopen是最好的哦。
我们再使用
代码如下
<?phpecho "<hr />";echo $_SERVER["HTTP_REFERER"];?>
-------------------------------------------------------------------
php curl伪造referer与来源IP非常的简单,今天做一个图片采集的也有做过,下面我把两个例子都整理一下,供大家参考。例子1
代码如下
[one.php]<?php$post_data = array ("user" => "gongwen","pwd" => "123456");$header_ip = array('CLIENT-IP:88.88.88.88','X-FORWARDED-FOR:88.88.88.88',);$referer='http://www.111cn.net';$ch = curl_init();curl_setopt ($ch, CURLOPT_URL, 'http://localhost/curl/two.PHP');//伪造来源referercurl_setopt ($ch,CURLOPT_REFERER,$referer);//伪造来源ipcurl_setopt($ch, CURLOPT_HTTPHEADER, $header_ip);//提交post传参curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);//加上这个表示执行curl_exec是把输出做为返回值,不会输出到浏览器curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);$out_put=curl_exec ($ch);curl_close ($ch);echo $out_put;[two.php]<?php//请求来源refererecho '[HTTP_REFERER]<br>';echo $_SERVER['HTTP_REFERER'];//请求来源ip//[注]此处的IP打印顺序是目前很多开源系统的IP获取顺序echo '<hr>[IP]<br>';echo $_SERVER['HTTP_CLIENT_IP'];echo '<br>';echo $_SERVER['HTTP_X_FORWARDED_FOR'];echo '<br>';echo $_SERVER['REMOTE_ADDR'];//POST数据echo '<hr>[POST]<br><pre>';var_dump($_POST);echo '</pre>';
浏览器访问one.php。页面打印如下:例子2
代码如下
function getImagesUrl( $url,$userinfo,$header){$ch = curl_init();$timeout = 1;curl_setopt ($ch, CURLOPT_URL, "$url");curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);curl_setopt ($ch, CURLOPT_REFERER, "http://www.baidu.com/");curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt ($ch, CURLOPT_USERAGENT, "$userinfo");curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);$contents = curl_exec($ch);curl_close($ch);//echo $contents;return $contents ;}function saveurl( $handle ,$filename){$fp = fopen($filename,"w");fwrite($fp,$handle);unset($fp);unset($handle);}$binfo =array('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; InfoPath.2; AskTbPTV/5.17.0.25589; Alexa Toolbar)','Mozilla/5.0 (Windows NT 5.1; rv:22.0) Gecko/20100101 Firefox/22.0','Mozilla/4.0 (compatible; MSIE 8.0; Windows
NT 5.1; Trident/4.0; .NET4.0C; Alexa Toolbar)','Mozilla/4.0(compatible; MSIE 6.0; Windows NT 5.1; SV1)',$_SERVER['HTTP_USER_AGENT']);//123.125.68.*//125.90.88.*$cip = '123.125.68.'.mt_rand(0,254);$xip = '125.90.88.'.mt_rand(0,254);$header = array('CLIENT-IP:'.$cip,'X-FORWARDED-FOR:'.$xip,);$u = $binfo[mt_rand(0,3)];$get_file = getImagesUrl($value,$u,$header);saveurl($get_file,'a.jpg');
文章地址: http://blog.csdn.net/aerchi/article/details/51644423
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: