Code in PHP to detect whether a geographical IP address is available_PHP tutorial

WBOY
Release: 2016-07-21 15:20:14
Original
845 people have browsed it

Copy code The code is as follows:

/******************************************
*
* Function name: curl_string ($url,$proxy)
* Function: Detect 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);//Set the IP 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 jump
curl_setopt ($ch, CURLOPT_TIMEOUT, 120); //Set Timeout
curl_setopt ( $ch, CURLOPT_AUTOREFERER, 1 ); // Automatically set 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 Failure: ' . curl_error($ch) ." -- ". $proxy."n", 3, MYMEDIA.'/log/'.date('Y-m-d').'_Err.log');
}else{
error_log(date("H:i:s") . ' Curl success: ' . $proxy."n", 3, MYMEDIA.'/log/'.date('Y-m-d' ).'_OK.log');
}
curl_close($ch);
return $result;
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325165.htmlTechArticleCopy the code as follows: /****************** ************************** * * Function name: curl_string ($url,$proxy) * Function: Detect proxy IP address * Author: Li Feilin *Date:...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!