PHP uses CURL to forge source IP address and source URL address program code-PHP source code

Source: Internet
Author: User
Using curl in php to forge the source IP address is a very good method. Next we will introduce an example of using php to forge the source IP address, however, the source of $ _ SERVER [REMOTE_ADDR] cannot be forged after testing. Using curl in php to forge the source IP address is a very good method. Next we will introduce an example of using php to forge the source IP address, however, the source of $ _ SERVER ["REMOTE_ADDR"] cannot be forged after testing.

Script ec (2); script

Test. php file

The Code is as follows:

Ob_start ();
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_URL, "http://www.xxx.cn/test/test2.php ");
Curl_setopt ($ ch, CURLOPT_HTTPHEADER, array ('x-FORWARDED-FOR: 1.1.1.1 ', 'client-IP: 2.2.2.2'); // counterfeit IP
Curl_setopt ($ ch, CURLOPT_REFERER, "http://www.111cn.net/"); // counterfeit source URL
Curl_setopt ($ ch, CURLOPT_HEADER, 1 );
Curl_exec ($ ch );
Curl_close ($ ch );

$ Out = ob_get_contents ();
Ob_clean ();
Echo $ out;

?>

The test2.php file code is as follows:

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 (). "HTTP_CLIENT_IP -:". $ _ SERVER ["HTTP_CLIENT_IP"]. "HTTP_X_FORWARDED_FOR -:". $ _ SERVER ["HTTP_X_FORWARDED_FOR"]. "REMOTE_ADDR -:". $ _ SERVER ["REMOTE_ADDR"]. "";
Echo"
Referer: ". $ _ SERVER [" HTTP_REFERER "];
?>

Execution result:

HTTP/1.1 200 OK
Server: DWS/01.03Z33
Date: Mon, 09 Jun 2014 09:27:09 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding


IP: 2.2.2.2 HTTP_CLIENT_IP-: 2.2.2.2 HTTP_X_FORWARDED_FOR-: 1.1.1.1
REMOTE_ADDR-: 127.0.0.1
Referer: http://www.111cn.net/

However, it is not possible to forge a scam:

$ _ SERVER ["REMOTE_ADDR"].

Therefore, we recommend that you use $ _ SERVER ["REMOTE_ADDR"] to record IP addresses.

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.