本文實例講述了PHP+Ajax實時自動檢測是否聯網的方法。分享給大家供大家參考。具體實現方法如下:
html部分代碼:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"php部分代碼:
?
1 2 3 4 5 6 7 8 9 10 11 public function getNetLink(){ header("cache-control:no-cache,must-revalidate"); header("Content-Type:text/html;charset=utf-8"); $file=fopen("http://www.baidu.com/", "r"); if (!$file){ $shownetlink = "<font color="red">網絡連接失敗</font>"; }else{ $shownetlink = "<font color="#06C">網絡連接正常</font>"; } echo $shownetlink; }新聞熱點
疑難解答