Skip to content

Instantly share code, notes, and snippets.

@52cik
Last active April 4, 2016 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 52cik/915ff0d8aff3ee9bc08fb6d26fc1f7c6 to your computer and use it in GitHub Desktop.
Save 52cik/915ff0d8aff3ee9bc08fb6d26fc1f7c6 to your computer and use it in GitHub Desktop.
php 伪造IP及来源
<?php
$headers = [ // 构造IP
'CLIENT-IP: 8.8.8.8',
'X-FORWARDED-FOR: 8.8.8.8',
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1:8000/server.php');
curl_setopt($ch, CURLOPT_REFERER, 'http://www.baidu.com/'); // 构造来路
curl_setopt($ch, CURLOPT_HTTPHEADER , $headers);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_exec($ch);
curl_close ($ch);
<?php
function GetIP(){
if(!empty($_SERVER['HTTP_CLIENT_IP']))
$cip = $_SERVER['HTTP_CLIENT_IP'];
else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
$cip = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if(!empty($_SERVER['REMOTE_ADDR']))
$cip = $_SERVER['REMOTE_ADDR'];
else
$cip = '无法获取!';
return $cip;
}
echo "访问IP: " . GetIP() . "\n";
echo "访问来路: " . @$_SERVER['HTTP_REFERER'] . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment