Php uses Curl to forge the client source IP_PHP tutorial

Source: Internet
Author: User
Php uses Curl to forge the client source IP address. 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 be forged, but many methods have been found 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.bKjia. c0m
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 address, provided that the service

The tool enables X_FORWARDED_FOR.

Test results: Create a PHP program on the server:

1. php requests index. php.
1. php code:

The code is as follows:

$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_URL, "http: // localhost/index. php ");
Curl_setopt ($ ch, CURLOPT_HTTPHEADER, array ('x-FORWARDED-FOR: 8.8.8.8 ', 'client-IP: 8.8.8.8 '));

// Construct an IP address
Curl_setopt ($ ch, CURLOPT_REFERER, "http://www.bKjia. c0m/"); // Construct a ro
Curl_setopt ($ ch, CURLOPT_HEADER, 1 );
$ Out = curl_exec ($ ch );
Curl_close ($ ch );


2. the php 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 ()."";
Echo "referer:". $ _ SERVER ["HTTP_REFERER"];

Echo "IP:". getClientIp ()."";
Echo "referer:". $ _ SERVER ["HTTP_REFERER"];

Forged successfully. Is this a good IP address change solution for the "ticket scalping" friends !!
Haha.

Result:
HTTP/1.1 200 OK Date: Wed, 03 Apr 2013 06:20:42 GMT Server: Apache/2.2.22 (Win32) PHP/5.3.13

X-Powered-By: PHP/5.3.13 Content-Length: 44 Content-Type: text/html
IP: 8.8.8.8
Referer: http://www.bKjia. c0m/

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.