</head>
<body onload="start();">
<h1>PHP+Ajax 实时自动检测是否联网</h1>
<p>当前网络状态:<span id="shownetlink"></span></p>
</body>
</html>
2,php 代码
代码示例:
<?php
//检测网络连接,是否已联网
public function getNetLink(){
header("cache-control:no-cache,must-revalidate");
header("Content-Type:text/html;charset=utf-8");
$file=fopen("http://www.jbxue.com/", "r");
if (!$file){
$shownetlink = "<font color=\"red\">网络连接失败</font>";
}else{
$shownetlink = "<font color=\"#06C\">网络连接正常</font>";
}
echo $shownetlink;
}