您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php判断远程资源是否存在的示例代码分析

2025/12/29 22:46:46发布12次查看
php判断远程资源是否存在的示例代码分析
<?php $url1='http://www.91hi.net/web/demo/1.jpg' //exists $url2='http://91hi.net/web/demo/www/jd/image/logo.png'; //not exists $get1=get_headers($url1); $get2=get_headers($url2); print_r($get1); print_r($get2);
返回结果:
array ( [0] => http/1.1 404 not found [1] => date: tue, 14 mar 2017 10:58:00 gmt [2] => server: apache [3] => vary: user-agent,accept-encoding [4] => connection: close [5] => content-type: text/html ) array ( [0] => http/1.1 200 ok [1] => date: tue, 14 mar 2017 10:58:00 gmt [2] => server: apache [3] => last-modified: wed, 09 nov 2016 08:57:06 gmt [4] => etag: "2162a05-13f5-540da70f97c80" [5] => accept-ranges: bytes [6] => content-length: 5109 [7] => vary: user-agent [8] => connection: close [9] => content-type: image/png ) 可以看到返回的http状态信息组成的一维数组.且第一个数组单元为响应状态信息.
于是乎,通过获取到的状态码,用来判断远程资源是否存在。
$statuscode=substr($get1[0], 9, 3); if($statuscode == 200 || $statuscode == 304){ echo "it's exists." }else{ echo "it's not exists." }
以上就是php判断远程资源是否存在的示例代码分析的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product