如何在PHP服务器端检查网站的网址是否有效? [英] How to PHP server-side check if a url of a web site is valid?
本文介绍了如何在PHP服务器端检查网站的网址是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经搜索了SO问题,但发现解决方案是基于调用ping
通过使用system
PHP函数执行的命令.
I've searched our SO questions but found solutions are based on calling ping
command executed from using system
PHP function.
我的Web主机服务器不允许我这样做.我该怎么办?
My web host server doesn't allow me to do that. What should I do?
请帮助, 南
更新
我需要从server side
检查.
推荐答案
If by a valid URL you mean one which does not 404, then you could use get_headers()
and look for 404
in the first returned array element.
$url = 'http://google.com';
list($status) = get_headers($url);
if (strpos($status, '404') !== FALSE) {
// URL is 404ing
}
或者,您可以寻找200
,这将是一个正常的快乐请求:)
Alternatively, you could look for 200
which would be a normal happy request :)
这篇关于如何在PHP服务器端检查网站的网址是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文