1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php $url1 = "http://w.skyfox.org/";//主网站 $url2 = "http://www.skyfox.org/"; //备用网站 $array = get_headers($url,1); if(preg_match('/200/',$array[0])){ //200为正常代码,经常见到的还有404,400,500等 echo "<script language='javascript' type='text/javascript'>"; echo "window.location.href='$url1'"; echo "</script>"; // echo "<pre/>"; // print_r($array); }else{ echo "<script language='javascript' type='text/javascript'>"; echo "window.location.href='$url2'"; echo "</script>"; } ?> |
转载请注明:天狐博客 » php判断http状态码判断网站可用性,跳转到备用网站