0
A
回答
1
您也可以使用多个卷曲的请求每次检查所有列表的更多更快。 Check here
1
看着卷曲。它允许你在php http://www.php.net/manual/en/function.curl-exec.php中拉出一个站点然后,只需检查响应中的状态代码或类似标题标签。
0
我自己是一个noob,但我会建议使用cURL。使用快速谷歌搜索发现下面的代码(我没有测试):
<?php
$statusCode = validate($_REQUEST['url']);
if ($statusCode==’200′)
echo ‘Voila! URL ‘.$_REQUEST['url'].
’ exists, returned code is :’.$statusCode;
else
echo ‘Opps! URL ‘.$_REQUEST['url'].
’ does NOT exist, returned code is :’.$statusCode;
function validateurl($url)
{
// Initialize the handle
$ch = curl_init();
// Set the URL to be executed
curl_setopt($ch, CURLOPT_URL, $url);
// Set the curl option to include the header in the output
curl_setopt($ch, CURLOPT_HEADER, true);
// Set the curl option NOT to output the body content
curl_setopt($ch, CURLOPT_NOBODY, true);
/* Set to TRUE to return the transfer
as a string of the return value of curl_exec(),
instead of outputting it out directly */
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute it
$data = curl_exec($ch);
// Finally close the handle
curl_close($ch);
/* In this case, we’re interested in
only the HTTP status code returned, therefore we
use preg_match to extract it, so in the second element
of the returned array is the status code */
preg_match(“/HTTP\/1\.[1|0]\s(\d{3})/”,$data,$matches);
return $matches[1];
}
?>
来源:http://www.ajaxapp.com/2009/03/23/to-validate-if-an-url-exists-use-php-curl/
相关问题
- 1. 变更链接href属性
- 2. Jsoup删除链接href属性与HREF
- 3. 验证href指向文件的链接
- 4. 用href属性中的空格链接
- 5. 在href属性中隐藏HTML链接
- 6. jQuery点击链接href属性
- 7. 儿童元素属性 - 链接href - jquery
- 8. JQuery更改链接tage的href属性
- 9. HTML链接href属性<a href="./">解释
- 10. HREF链接为<abc>,如何把href属性里面
- 11. 验证属性
- 12. 验证属性
- 13. 属性验证属性
- 14. 验证:坏值首先为属性的rel元素链接
- 15. 使用Selenium IDE来验证链接标题属性
- 16. void验证独特性:链接
- 17. Moq验证链接
- 18. XSD属性验证
- 19. MSBuild验证属性
- 20. jQuery验证属性
- 21. “RequiredAsSet”验证属性
- 22. ServiceStack,验证属性
- 23. 可以接受属性验证吗?
- 24. 如何验证JPA连接属性?
- 25. 上传前验证属性接受
- 26. 是否存在网站链接(href)验证服务?
- 27. 验证多发性属性
- 28. 将验证属性注入验证属性Web Api Asp.Net Core
- 29. MVC2验证模型还没有验证属性的属性
- 30. XML验证不验证基于另一个属性的属性
“有效页面”的意思是不是http状态码= 200? – safarov 2012-03-23 17:19:46
是的,我想我会想要一个200.只是不是404或任何其他错误的错误代码。我有一个具有特定URL的产品列表,如果供应商(如J.C. Penny等)更改它们,则这些产品的链接会发生变化。我不想将我的客户发送到“旧”链接,因此我不想输出这些“过期”或“无效”网址。那有意义吗? – jrubins 2012-03-23 17:23:26
你不想每次都在链接输出之前这样做......你应该用'cron'或类似的方式将它作为一个预定的后台任务来运行。 – prodigitalson 2012-03-23 17:29:30