Home  >  Article  >  Backend Development  >  PHP curl disguise source information

PHP curl disguise source information

*文
*文Original
2017-12-23 16:08:312976browse

In some cases, we need to use CURL to simulate requests to complete something. But the reality is always somewhat different from the ideal. The other party's server may have some restrictions on the source information requested. How should we deal with this situation? This article will tell you how to let curl disguise source information to deceive the server's source information restrictions.

[one.php]

<?php
$post_data = array (
"user" => "admin",
"pwd" => "123456"
);
$header_ip = array(
  &#39;CLIENT-IP:8.8.8.8&#39;,
  &#39;X-FORWARDED-FOR:8.8.8.8&#39;,
);
$referer=&#39;http://www.liangshao.com&#39;;
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, &#39;http://localhost/curl/two.PHP&#39;);
//伪造来源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 &#39;[HTTP_REFERER]<br>&#39;;
echo $_SERVER[&#39;HTTP_REFERER&#39;];
 //请求来源ip
 //[注]此处的IP打印顺序是目前很多开源系统的IP获取顺序 
 echo &#39;<hr>[IP]<br>&#39;;
 echo $_SERVER[&#39;HTTP_CLIENT_IP&#39;];
 echo &#39;<br>&#39;;
 echo $_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;];
 echo &#39;<br>&#39;;
 echo $_SERVER[&#39;REMOTE_ADDR&#39;];
 //POST数据
 echo &#39;<hr>[POST]<br><pre class="brush:php;toolbar:false">&#39;;
 var_dump($_POST);
 echo &#39;
';

Related reading;

php CURL Get cookies to simulate login method code example

php curl error troubleshooting method detailed explanation

PHP curl simulates logging into a website with verification code

The above is the detailed content of PHP curl disguise source information. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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