PHP curl counterfeit IP address and header information code example
This article mainly introduces PHP curl counterfeit IP address and header information code examples. This article provides the server and client implementation code, provides the counterfeit function and Server Detection Code. For more information, see
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
The Code is as follows:
$ Headers ['client-ip'] = '192. 103.229.40 ';
$ Headers ['x-FORWARDED-FOR '] = '2017. 103.229.40 ';
$ HeaderArr = array ();
Foreach ($ headers as $ n => $ v ){
$ HeaderArr [] = $ n. ':'. $ v;
}
Ob_start ();
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_URL, "http: // localhost/curl/server. php ");
Curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ headerArr); // construct an IP address
Curl_setopt ($ ch, CURLOPT_REFERER, "http://www.163.com/"); // construct a path
Curl_setopt ($ ch, CURLOPT_HEADER, 1 );
Curl_exec ($ ch );
Curl_close ($ ch );
$ Out = ob_get_contents ();
Ob_clean ();
Echo $ out;
Then there is server. php
The Code is as follows:
Function GetIP (){
If (! Emptyempty ($ _ SERVER ["HTTP_CLIENT_IP"])
$ Cip = $ _ SERVER ["HTTP_CLIENT_IP"];
Else if (! Emptyempty ($ _ SERVER ["HTTP_X_FORWARDED_FOR"])
$ Cip = $ _ SERVER ["HTTP_X_FORWARDED_FOR"];
Else if (! Emptyempty ($ _ SERVER ["REMOTE_ADDR"])
$ Cip = $ _ SERVER ["REMOTE_ADDR"];
Else
$ Cip = "cannot be obtained! ";
Return $ cip;
}
Echo"
Access IP: ". GetIP ()."
";
Echo"
Access path: ". $ _ SERVER [" HTTP_REFERER "];