PHP Curl Forged IP Address and header information code example _php Tutorial

Source: Internet
Author: User

PHP Curl Forged IP Address and header information code example


This article mainly introduces the PHP curl forged IP Address and header information code example, this article gives the server-side and client implementation code, provide the forgery function and server-side detection code, the need for friends can refer to the following

Although Curl is powerful, but can only forge $_server["Http_x_forwarded_for", for most IP address detection procedures, $_server["REMOTE_ADDR"] is difficult to forge:

The first is the client.php code.

The code is as follows:

$headers [' client-ip '] = ' 202.103.229.40 ';

$headers [' x-forwarded-for '] = ' 202.103.229.40 ';

$HEADERARR = Array ();

foreach ($headers as $n = = $v) {

$HEADERARR [] = $n. ': '. $v;

}

Ob_start ();

$ch = Curl_init ();

curl_setopt ($ch, Curlopt_url, "http://localhost/curl/server.php");

curl_setopt ($ch, Curlopt_httpheader, $HEADERARR); Constructing IP

curl_setopt ($ch, Curlopt_referer, "http://www.163.com/"); Construction route

curl_setopt ($ch, Curlopt_header, 1);

Curl_exec ($ch);

Curl_close ($ch);

$out = Ob_get_contents ();

Ob_clean ();

Echo $out;

And then the server.php.

The code is as follows:

function GetIP () {

if (!emptyempty ($_server["Http_client_ip"))

$cip = $_server["Http_client_ip"];

else if (!emptyempty ($_server["http_x_forwarded_for"]))

$cip = $_server["Http_x_forwarded_for"];

else if (!emptyempty ($_server["REMOTE_ADDR"]))

$cip = $_server["REMOTE_ADDR"];

Else

$CIP = "Cannot get!";

return $CIP;

}

echo "
Access IP: ". GetIP (). "
";

echo "
Access route: ". $_server[" Http_referer "];

http://www.bkjia.com/PHPjc/990994.html www.bkjia.com true http://www.bkjia.com/PHPjc/990994.html techarticle PHP Curl Forged IP Address and header information code example this article mainly introduces the PHP curl forged IP Address and header information code example, this article gives the server-side and the client implementation code, provide ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.