不要只检查域名
太棒了,又是我使用了这个功能。
我的功能可以正常工作。
function http_file_exists($url)
{
$f = @fopen($url,"r");
if($f)
{
fclose($f);
return true;
}
return false;
}
这就是用法:
if ($submit || $preview || $refresh)
{
$post_data['your_url'] = "http://www.google.com/this"; //remove the equals and url value if using in real post
$your_url = $post_data['your_url'];
$your_url_exists = (isset($your_url)) ? true : false;
$your_url = preg_replace(array('#&\#46;#','#&\#58;#','/\[(.*?)\]/'), array('.',':',''), $your_url);
if ($your_url_exists && http_file_exists($your_url) == true)
{
trigger_error('exists!');
}
如何让它检查整个 url 而不仅仅是域名?例如http://www.google.com/this
Soooo it's me again with this function..
I have the function working.
function http_file_exists($url)
{
$f = @fopen($url,"r");
if($f)
{
fclose($f);
return true;
}
return false;
}
And this is the usage :
if ($submit || $preview || $refresh)
{
$post_data['your_url'] = "http://www.google.com/this"; //remove the equals and url value if using in real post
$your_url = $post_data['your_url'];
$your_url_exists = (isset($your_url)) ? true : false;
$your_url = preg_replace(array('#&\#46;#','#&\#58;#','/\[(.*?)\]/'), array('.',':',''), $your_url);
if ($your_url_exists && http_file_exists($your_url) == true)
{
trigger_error('exists!');
}
How do I let it check the whole url and not the domain name only ? for example http://www.google.com/this
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
测试的网址是 http://www.google.com/abadurltotest
下面的代码源 = 确定是否存在的最快方法是什么网址PHP 中存在吗?
将顶部代码添加到functions_posting.php 中,替换之前的函数
url tested is http://www.google.com/abadurltotest
source of code below = What is the fastest way to determine if a URL exists in PHP?
add the top code to functions_posting.php replacing previous function
使用curl 并检查HTTP 状态代码。如果不是 200 - 很可能该 url 不存在或无法访问。
另请注意,这
没有任何意义。看来您想要
或只是检查
$your_url
而不是$your_url_exists
Use curl and check the HTTP status code. if it's not 200 - most likely the url doesn't exist or inaccessible.
also note that
makes no sense. It seems you want
or just check
$your_url
instead of$your_url_exists