Code in PHP to detect if a geographic IP address is available _php tutorial

Source: Internet
Author: User
Copy CodeThe code is as follows:
/********************************************
*
* Function Name: curl_string ($url, $proxy)
* Function: Detect proxy IP Address
* Author: Li Fei 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 the IP to be accessed
curl_setopt ($ch, curlopt_useragent, $user _agent);//browser used by the impersonated user
@curl_setopt ($ch, curlopt_followlocation, 1); Use Auto Jump
curl_setopt ($ch, Curlopt_timeout, 120); Setting the time-out period
curl_setopt ($ch, Curlopt_autoreferer, 1); Set Referer automatically

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 succeeds: '. $proxy. " \ n ", 3, Mymedia." /log/'. Date (' y-m-d '). ' _ok.log ');
}
Curl_close ($ch);
return $result;
}

http://www.bkjia.com/PHPjc/325165.html www.bkjia.com true http://www.bkjia.com/PHPjc/325165.html techarticle Copy the code code as follows:/******************************************** * * Function Name: curl_string ($url, $proxy) * Function: Detect proxy IP Address * Author: Li Fei Lin * Date: ...

  • Related Article

    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.