php curl伪造referer与来源IP非常的简单,今天做一个图片采集的也有做过,下面我把两个例子都整理一下,供大家参考.
例子1,代码如下:
<?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.phprm.com'; $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, 'http://localhost/curl/two.PHP'); //伪造来源referer curl_setopt ($ch,CURLOPT_REFERER,$referer); //伪造来源ip curl_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 //请求来源referer echo '[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 class="brush:php;toolbar:false">'; var_dump($_POST); echo '';
例子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.phprm.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');
即可.
教程地址:
欢迎转载!但请带上文章地址^^

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1
Easy-to-use and free code editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment