- $ch = Curl_init ();
- $url = "http://localhost/target_ip.php";
- $header = Array (
- ' client-ip:58.68.44.61 ',
- ' x-forwarded-for:58.68.44.61 ',
- );
- curl_setopt ($ch, Curlopt_url, $url);
- curl_setopt ($ch, Curlopt_httpheader, $header);
- curl_setopt ($ch, curlopt_returntransfer,true);
- $page _content = curl_exec ($ch);
- Curl_close ($ch);
- echo $page _content;
- ?>
Copy Code
The requested target file---target_ip.php:
- echo getenv (' http_client_ip ');
- echo getenv (' http_x_forwarded_for ');
- echo getenv (' remote_addr ');
- ?>
Copy Code
Target file target_ip inside the IP print order is currently many open source system IP get sequential access fake_ip.php, see the result: 58.68.44.6158.68.44.61127.0.0.1
Finally, we provide two small examples. Example 1:
- $ch = Curl_init ();
- curl_setopt ($ch, Curlopt_url, "http://localhost/2.php");
- curl_setopt ($ch, Curlopt_httpheader, Array (' x-forwarded-for:8.8.8.8 ', ' client-ip:8.8.8.8 ')); Constructing IP
- curl_setopt ($ch, Curlopt_referer, "http://bbs.it-home.org/"); Construction route
- curl_setopt ($ch, Curlopt_header, 1);
- $out = curl_exec ($ch);
- Curl_close ($ch);
- ?>
Copy Code
Example 2:
- 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"];
- ?>
Copy Code |