php curl Example code for forging IP source_PHP tutorial

WBOY
Release: 2016-07-21 15:15:03
Original
729 people have browsed it

The file fake_ip.php where curl makes the request:
Code

Copy the code The code is as follows:

< ?php
$ch = curl_init();
$url = "http://localhost/target_ip.php";
$header = array(
'CLIENT-IP:58.68.44.61' ,
'X-FORWARDED-FOR:58.68.44.61',
);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
$page_content = curl_exec($ch);
curl_close($ch);
echo $page_content;
?>

Requested target file target_ip.php:
Copy code The code is as follows:

echo getenv('HTTP_CLIENT_IP');
echo getenv('HTTP_X_FORWARDED_FOR');
echo getenv('REMOTE_ADDR');
?>

Target file target_ip The IP printing order inside is the current IP acquisition order of many open source systems
Visit fake_ip.php and see the result:
58.68.44.61
58.68.44.61
127.0.0.1
Example
CURL is indeed very powerful and can forge IPs and sources.
1.php requests 2.php.

1.php code:

Copy code The code is as follows:

$ch = curl_init ();
curl_setopt($ch, CURLOPT_URL, "http://localhost/2.php");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:8.8.8.8', 'CLIENT-IP:8.8.8.8')); //Construct IP
curl_setopt($ch, CURLOPT_REFERER, "http://www.jb51.net/ "); //Construct source
curl_setopt( $ch, CURLOPT_HEADER, 1);
$out = curl_exec($ch);
curl_close($ch);


2.php code is as follows:

Copy code The code is as follows:

function getClientIp() {
if (!empty($_SERVER["HTTP_CLIENT_IP "]))
$ip = $_SERVER["HTTP_CLIENT_IP"];
else if (!empty($_SERVER["HTTP_X_FORWARDED_FOR"]))
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
else if (!empty($_SERVER["REMOTE_ADDR"]))
$ip = $_SERVER["REMOTE_ADDR"];
else
$ip = "err";
return $ip;
}
echo "IP: " . getClientIp() . "";
echo "referer: " . $_SERVER["HTTP_REFERER"];

fake Success, does this provide a good IP change solution for friends who "fake tickets"

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326165.htmlTechArticleThe file fake_ip.php requested by curl: The code copy code is as follows: ?php $ch = curl_init(); $url = "http://localhost/target_ip.php"; $header = array( 'CLIENT-IP:58.68.44.61', '...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!