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.