2011-12-19 44 views
0

我收到了一些链接,其中一些链接是rapidshare,一些链接是其他上传主机。 如何检查链接上的文件是否仍在工作?使用php检查主机的链接

我试着用curl和file_get_contents。 在一些主机上curl正在工作,而其他file_get_contents正在工作,但大多数不会返回页面源代码,所以我无法搜索字符串“已删除”或类似的东西。

有没有办法做到这一点?

编辑:这里是新的代码,仍然无法工作:

function curl_download($Url){ 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $Url); 
$agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"; 
curl_setopt($ch, CURLOPT_USERAGENT, $agent); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch,CURLOPT_VERBOSE,false); 
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE); 
    curl_setopt($ch,CURLOPT_SSLVERSION,3); 
    curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, FALSE); 
curl_setopt($ch, CURLOPT_TIMEOUT, 0); 
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); 
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); 
$output = curl_exec($ch); 
curl_close($ch); 
return $output; 
+0

什么是你的代码?他们返回什么? –

回答

2
 
function Visit($url){ 
     $agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"; 
     $ch=curl_init(); 
     curl_setopt ($ch, CURLOPT_URL,$url); 
     curl_setopt($ch, CURLOPT_USERAGENT, $agent); 
     curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt ($ch,CURLOPT_VERBOSE,false); 
     curl_setopt($ch, CURLOPT_TIMEOUT, 5); 
     curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE); 
     curl_setopt($ch,CURLOPT_SSLVERSION,3); 
     curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, FALSE); 
     $page=curl_exec($ch); 
     //echo curl_error($ch); 
     $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
     curl_close($ch); 
     if($httpcode>=200 && $httpcode<300) return true; 
     else return false; 
} 
if (Visit("http://www.google.com")) 
     echo "Website OK"."n"; 
else 
     echo "Website DOWN"; 

+0

它会完成这项工作,但它看起来有点过头了。 [CURL](http://php.net/manual/en/book.curl.php)绝对是答案 – adlawson

+0

感谢您的评论。 但是,它仍然无法工作。 它没有得到一些主机的源代码,或者它只是获得一些源代码。 我必须得到整个来源才能搜索单词“已删除”等。 – user1104615

+0

@user诀窍是查看HTTP响应代码。如果文件不存在,主机*应该用404代码或类似的代码进行响应。无需查看实际的页面内容。这些网站实际上是否这样做是一个不同的问题。 – deceze