Code _php techniques used in PHP to detect whether a geographic IP address is available

Source: Internet
Author: User
Tags curl
Copy Code code as follows:

/********************************************
*
* Function Name: curl_string ($url, $proxy)
* Role: Detection agent IP Address
* Author: Plum Lin
* 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 IP to access
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 time
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 failed: '. 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;
}

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.