Php uses Curl to forge the client source IP address

Source: Internet
Author: User
I found many methods on the internet to use Curl to forge the client source IP address, almost all of which use the curl function. later I verified that this function is powerful, not only can the client source IP address be forged, but also

I found many methods on the internet to use Curl to forge the client source IP address, almost all of which use the curl function. later I verified that this function is powerful, not only can the client source IP address be forged, but also the proxy IP address be forged. let's look at the code.

Generally, the server can obtain the client IP address in three cases.

1. if no proxy is used:

# Http://www.phpfensi.com

REMOTE_ADDR = customer IP

HTTP_VIA = null

HTTP_X_FORWARDED_FOR = null

2. when the proxy is used and the proxy server has the IP address of the forwarding client configured:

REMOTE_ADDR = proxy server IP address

HTTP_VIA = proxy server IP address

HTTP_X_FORWARDED_FOR = customer IP

The HTTP_VIA and HTTP_X_FORWARDED_FOR values can be customized by adding the Header to hide the client IP, provided that X_FORWARDED_FOR is enabled on the server.

Test results: Create a PHP program on the server.

Example code 1: The code is as follows:

  1. $ Ch = curl_init ();
  2. Curl_setopt ($ ch, CURLOPT_URL, "http: // localhost/index. php ");
  3. Curl_setopt ($ ch, CURLOPT_HTTPHEADER, array ('x-FORWARDED-FOR: 8.8.8.8 ', 'client-IP: 8.8.8.8 '));
  4. // Construct an IP address
  5. Curl_setopt ($ ch, CURLOPT_REFERER, "http://www.phpfensi.com/"); // Construct a path
  6. Curl_setopt ($ ch, CURLOPT_HEADER, 1 );
  7. $ Out = curl_exec ($ ch );
  8. Curl_close ($ ch );

Example code 2: php code:

  1. Function getClientIp (){
  2. If (! Emptyempty ($ _ SERVER ["HTTP_CLIENT_IP"])
  3. $ Ip = $ _ SERVER ["HTTP_CLIENT_IP"];
  4. Else if (! Emptyempty ($ _ SERVER ["HTTP_X_FORWARDED_FOR"])
  5. $ Ip = $ _ SERVER ["HTTP_X_FORWARDED_FOR"];
  6. Else if (! Emptyempty ($ _ SERVER ["REMOTE_ADDR"])
  7. $ Ip = $ _ SERVER ["REMOTE_ADDR"];
  8. Else
  9. $ Ip = "err ";
  10. Return $ ip;
  11. }
  12. Echo "IP:". getClientIp ()."";
  13. Echo "referer:". $ _ SERVER ["HTTP_REFERER"];
  14. Echo "IP:". getClientIp ()."";
  15. Echo "referer:". $ _ SERVER ["HTTP_REFERER"];

Forged successfully. does this provide a good IP address change solution for the "fake ticket" friends? haha.

Result:

  1. HTTP/1.1 200 OK Date: Wed, 03 Apr 2013 06:20:42 GMT Server: Apache/2.2.22 (Win32) PHP/5.3.13
  2. X-Powered-By: PHP/5.3.13 Content-Length: 44 Content-Type: text/html
  3. IP: 8.8.8.8

Referer: http://www.phpfensi.com/

The following describes the curl function.

List of curl-related functions:

Curl_init-initialize a CURL session

Curl_setopt-set an option for CURL calls

Curl_exec-execute a CURL session

Curl_close-close a CURL session

Curl_version-returns the current CURL version

1> curl_init-initialize a CURL session

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.