PHPcurl: Counterfeit IP address and header information code instance PHP curl: Counterfeit IP address and header information code instance
// Author http://www.lai18.com $ headers ['client-IP'] = '2017. 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 IPcurl_setopt ($ ch, CURLOPT_REFERER," http://www.163.com/"); // Construct the Origin curl_setopt ($ ch, CURLOPT_HEADER, 1); curl_exec ($ ch); curl_close ($ ch); $ out = ob_get_contents (); ob_clean (); echo $ out;
2.Then there is server. php
// Author http://www.lai18.comfunction 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 "];
The above is the content of the PHP curl counterfeit IP address and header information code instance. For more information, see PHP Chinese network (www.php1.cn )!