How to automatically detect whether PHP Ajax is connected to the Internet in real time
This example describes the method of PHP Ajax to automatically detect whether it is connected to the Internet in real time. Share it with everyone for your reference. The specific implementation method is as follows:
HTML part code:
?
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
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
PHP Ajax实时自动检测是否联网
PHP Ajax实时自动检测是否联网
当前网络状态:
|
1
2
3
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 = "网络连接失败";
}else{
$shownetlink = "网络连接正常";
}
echo $shownetlink;
}
|
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
|
<🎜>"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
PHP Ajax automatically detects whether the Internet is connected in real time
PHP Ajax automatically detects whether the Internet is connected in real time
Current network status:
|
PHP part code:
?
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 = "Network connection failed";
}else{
$shownetlink = "Network connection is normal";
}
echo $shownetlink;
}
|
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/1025328.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1025328.htmlTechArticleHow PHP Ajax automatically detects whether it is connected to the Internet in real time. This example describes how PHP Ajax can automatically detect whether it is connected to the Internet in real time. Share it with everyone for your reference. The specific implementation method is as follows:...