php检查URL是否有效

samool 发布暂无评论7183 阅读

AI摘要

本文介绍了一个PHP函数,用于检查URL是否有效。函数首先检查URL是否包含http://,如果没有则添加。然后使用get_headers函数获取URL的头部信息,通过检查返回的状态码判断URL是否存在。如果状态码为404,则输出“此地址不存在”;否则输出“此地址正确”。
function checkUrl($url){
    if(stripos($url,'http://') === FALSE){
        $url = 'http://'.$url;
    }
    @$rs = get_headers($url);
    if($rs){
        if(stripos($rs[0],'404') !== FALSE){
            echo '此地址不存在';
        }else{
            echo '此地址正确';
        }
    }else{
        echo '此地址不存在';
    }
}

  1. 01PHP2Shell 重大安全漏洞事件深度分析报告2026-10-23
  2. 02代码测试2020-07-30
  3. 03php json转换为数组调用的问题处理2020-05-05
  4. 04PHP date() 函数可实现的功能列表2020-03-21
  5. 05PHP 文件分块下载实例2019-12-26
  6. 06php实现ipv6地址转换成数字INT类型存储数据库中2019-12-04
  7. 07PHP和MySQL中IPV4地址与INT的互相转换2019-12-04
  8. 08phpGrace 目录结构、命名规则2019-11-12
  9. 09phpGrace环境支持2019-11-12
  10. 10[PHP开源框架]phpGrace - 轻快的实力派!2019-11-12
COMMENTS / 一纸留言

读者留言 0 条

一纸留言,便是山水间的一次相逢。

还没有留言,欢迎写下第一段交流。

WRITE A COMMENT

写下你的留言