Php code used to check whether a geographic IP address is available. For more information, see
The code is as follows:
/*************************************** *****
*
* Function name: curl_string ($ url, $ proxy)
* For use: check the proxy IP address
* Author: Li feilin
* Date: 2011-11-09
*
**************************************** ****/
Function curl_string ($ url, $ proxy)
{
$ User_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv: 1.9.0.5) Gecko/2008120122 Firefox/3.0.5 FirePHP/0.2.1 ";
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_PROXY, $ proxy );
Curl_setopt ($ ch, CURLOPT_URL, $ url); // you can specify the IP address to be accessed.
Curl_setopt ($ ch, CURLOPT_USERAGENT, $ user_agent); // simulate the browser used by the user
@ Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1); // use automatic redirect
Curl_setopt ($ ch, CURLOPT_TIMEOUT, 120); // Set the timeout value.
Curl_setopt ($ ch, CURLOPT_AUTOREFERER, 1); // automatically sets Referer
Curl_setopt ($ ch, CURLOPT_COOKIEJAR, 'C: \ cookie.txt ');
Curl_setopt ($ ch, CURLOPT_HEADER, 1 );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1 );
Curl_setopt ($ ch, CURLOPT_TIMEOUT, 10 );
$ Result = curl_exec ($ ch );
// Check if any error occured
If ($ result = false)
{
Error_log (date ("H: I: s "). 'curl failed :'. curl_error ($ ch ). "--". $ proxy. "\ n", 3, MYMEDIA. '/log /'. date ('Y-m-D '). '_ Err. log ');
} Else {
Error_log (date ("H: I: s "). 'curl successful :'. $ proxy. "\ n", 3, MYMEDIA. '/log /'. date ('Y-m-D '). '_ OK. log ');
}
Curl_close ($ ch );
Return $ result;
}