PHP uses curl to forge IP address and header information

Source: Internet
Author: User
PHP uses curl to forge IP address and header information

Although curl is powerful, it can only forge $ _ SERVER ["HTTP_X_FORWARDED_FOR"]. for most IP address detection programs, it is difficult to forge $ _ SERVER ["REMOTE_ADDR:

First, the client. php code

01 $ Headers ['client-IP'] = '192. 103.229.40 ';
02 $ Headers ['X-FORWARDED-FOR '] = '2017. 103.229.40 ';
03
04 $ HeaderArr = array ();
05 Foreach ($ headers as $ n => $ v ){
06 $ HeaderArr [] = $ n. ':'. $ v;
07 }
08
09 Ob_start ();
10 $ Ch = curl_init ();
11 Curl_setopt ($ ch, CURLOPT_URL, "http: // localhost/curl/server. php ");
12 Curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ headerArr); // Construct an IP address
13 Curl_setopt ($ ch, CURLOPT_REFERER, "http://www.163.com/"); // Construct a path
14 Curl_setopt ($ ch, CURLOPT_HEADER, 1 );
15
16 Curl_exec ($ ch );
17 Curl_close ($ ch );
18 $ Out = ob_get_contents ();
19 Ob_clean ();
20
21 Echo $ out;

Then there is server. php

01 Function GetIP (){
02 If (! Emptyempty ($ _ SERVER ["HTTP_CLIENT_IP"])
03 $ Cip = $ _ SERVER ["HTTP_CLIENT_IP"];
04 Else if (! Emptyempty ($ _ SERVER ["HTTP_X_FORWARDED_FOR"])
05 $ Cip = $ _ SERVER ["HTTP_X_FORWARDED_FOR"];
06 Else if (! Emptyempty ($ _ SERVER ["REMOTE_ADDR"])
07 $ Cip = $ _ SERVER ["REMOTE_ADDR"];
08 Else
09 $ Cip = "cannot be obtained! ";
10 Return $ cip;
11 }
12 Echo"
Access IP: ". GetIP ()."
";
13 Echo"
Access path: ". $ _ SERVER [" HTTP_REFERER "];

Curl, PHP, header

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.