Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP服务器端检查网站的url是否有效?_Php_Validation_Url_Server Side - Fatal编程技术网

如何在PHP服务器端检查网站的url是否有效?

如何在PHP服务器端检查网站的url是否有效?,php,validation,url,server-side,Php,Validation,Url,Server Side,我搜索了我们的SO问题,但发现解决方案基于使用systemPHP函数调用ping命令 我的web主机服务器不允许我这样做。我该怎么办 请帮忙, 南 更新 我需要从服务器端进行检查尝试以下操作: //checking if the site exists by fopen, instead of file_get_contents to speed it up $url = "URL"; //your url goes in this place instead of nabtron.com

我搜索了我们的SO问题,但发现解决方案基于使用
system
PHP函数调用
ping
命令

我的web主机服务器不允许我这样做。我该怎么办

请帮忙, 南

更新

我需要从
服务器端进行检查

尝试以下操作:

//checking if the site exists by fopen, instead of file_get_contents to speed it up

$url = "URL"; //your url goes in this place instead of nabtron.com

if (@fopen($url,"r")) {
echo "<b>".$url."</b> is accessible<br />";
}
//用fopen检查站点是否存在,而不是用file\u get\u contents来加快速度
$url=“url”//你的url放在这里,而不是nabtron.com
如果(@fopen($url,“r”)){
回显“$url.”是可访问的
; }
如果有效URL指的是不包含404的URL,则可以使用并在第一个返回的数组元素中查找
404

$url = 'http://google.com';
list($status) = get_headers($url);
if (strpos($status, '404') !== FALSE) {
   // URL is 404ing
}

或者,您可以查找
200
,这将是一个正常的愉快请求:)

更多的上下文将有助于找到一个好的解决方案。您对此的确切用例是什么?您需要验证URL的哪些内容?URL是否需要是可访问的,或者只是有效的?