正文 1197字数 383,632阅读

方法1, $url = ‘http://www.lizhenqiu.com'; $ch = curl_init(); $timeout = 10; curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $contents = curl_exec($ch); if(false == $contents) { echo ‘Curl error: ‘ . curl_error($ch); } else { …. } 方法2 curl_getinfo($ch, CURLINFO_HTTP_CODE); 方法3 <?php ini_set('default_socket_timeout', 3); /*超时控制(3秒)*/ $url = '这里填对地址就pass,错就Timeout'; if($data = file_get_contents($url)) { echo 'Pass'; }else { echo 'Timeout'; } //End_php 方法4(js) <script language= "javascript"> function getURL(url) { var xmlhttp = new ActiveXObject( "Microsoft.XMLHTTP"); xmlhttp.open("GET", url, false); xmlhttp.send(); if(xmlhttp.readyState==4) { if(xmlhttp.Status != 200) alert("不存在"); return xmlhttp.Status==200; } return false; } </script> <a href= "http://www.lizhenqiu.com " onclick= "return getURL(this.href) "> csdn </a>
Run code
Cut to clipboard