Home > php教程 > PHP源码 > 检查代理IP的可用性!

检查代理IP的可用性!

PHP中文网
Release: 2016-05-25 17:12:03
Original
1215 people have browsed it

1. [PHP]代码    

  
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);//设置要访问的IP
	curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);//模拟用户使用的浏览器 
	@curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 ); // 使用自动跳转  
  	curl_setopt ( $ch, CURLOPT_TIMEOUT, 120 ); //设置超时时间
  	curl_setopt ( $ch, CURLOPT_AUTOREFERER, 1 ); // 自动设置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 失败: ' . curl_error($ch) ." -- ". $proxy."\n", 3, MYMEDIA.'/log/'.date('Y-m-d').'_Err.log');
	}else{
		error_log(date("H:i:s") . ' Curl 成功: ' . $proxy."\n", 3, MYMEDIA.'/log/'.date('Y-m-d').'_OK.log');
	}
	curl_close($ch);
	return $result;
}
Copy after login

                   

                   

Related labels:
php
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template