curl虽然功能强大,但是只能伪造$_SERVER["HTTP_X_FORWARDED_FOR"],对于大多数IP地址检测程序来说,$_SERVER["REMOTE_ADDR"]很难被伪造:
首先是client.php的代码
01 |
$headers['CLIENT-IP'] = '202.103.229.40'; |
02 |
$headers['X-FORWARDED-FOR'] = '202.103.229.40'; |
05 |
foreach( $headers as $n => $v ) { |
06 |
$headerArr[] = $n .':' . $v; |
12 |
curl_setopt ($ch, CURLOPT_HTTPHEADER , $headerArr ); //构造IP |
14 |
curl_setopt( $ch, CURLOPT_HEADER, 1); |
18 |
$out = ob_get_contents(); |
然后是server.php
02 |
if(!emptyempty($_SERVER["HTTP_CLIENT_IP"])) |
03 |
$cip = $_SERVER["HTTP_CLIENT_IP"]; |
04 |
else if(!emptyempty($_SERVER["HTTP_X_FORWARDED_FOR"])) |
05 |
$cip = $_SERVER["HTTP_X_FORWARDED_FOR"]; |
06 |
else if(!emptyempty($_SERVER["REMOTE_ADDR"])) |
07 |
$cip = $_SERVER["REMOTE_ADDR"]; |
12 |
echo "<br>访问IP: ".GetIP()."<br>"; |
13 |
echo "<br>访问来路: ".$_SERVER["HTTP_REFERER"]; |