例子1
例子2
上面的例子只是验证url是不是正常的不代表是否可以访问了,我们可以使用如curl函数进行方法
$url = http://www.phprm.com ;$curl = curl_init($url);curl_setopt($curl, curlopt_nobody, true);$result = curl_exec($curl);if ($result !== false) { $statuscode = curl_getinfo($curl, curlinfo_http_code); if ($statuscode == 404) { echo url not exists } else { echo url exists; } }else{ echo url not exists;}
除了这个函数还可以使用php的很多函数如 file、file_get_contents()、fopen函数来进行检测了。
