我是靠谱客的博主 时尚嚓茶,这篇文章主要介绍php怎么实现五秒后跳转,现在分享给大家,希望可以做个参考。

本文操作环境:Windows7系统、PHP7.1版、Dell G3电脑。

php怎么实现五秒后跳转?

PHP 5秒后自动跳转到某页面:

history.go(-2); //javaScript代码,后退两个页面。

setTimeout("playSec("+num+")",1000); //JavaScript代码,定时器,一秒后调用playSec()函数。

  • success.php 操作成功页面

  • error.php 操作失败页面

1、success.php 操作成功页面

复制代码
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
41
42
43
44
45
46
47
48
49
50
51
<?php $message=urldecode($_GET["message"]); $url=trim($_GET["url"]); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>操作成功</title> <style type="text/css"> *{margin:0px;padding:0px;} .box{ width:450px; border:1px solid #f0f0f0; background:#FFFFCC; margin:100px auto; padding:20px; font-size:14px; line-height:180%; color:#444; } h2{margin-bottom:10px;} #time{color:#FF0000;} .color2{color:#0099FF;} a.a1:link,a.a1:visited{color:#0099FF;text-decoration:none;} a.a1:hover{color:#FF0000;text-decoration:underline;} </style> </head> <body> <div class="box"> <h2 align="center">操作成功</h2> <p><b>提示:<?php echo $message;?></b></p> <p>系统将在 <span id="time">3</span> 秒钟后自动跳转,如果不想等待,请点击 <a class="a1" href="<?php echo $url?>">这里</a> 跳转。</p> </div> </body> </html> <script language="javascript"> function playSec(num) { time.innerText=num; if(--num >0) { setTimeout("playSec("+num+")",1000); //设置定时器,一秒后调用playSec()函数 }else { location.href="<?php echo $url?>"; //跳转到其他页面 } } playSec(3); </script>
登录后复制

2、error.php 操作失败页面

复制代码
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
41
42
43
44
45
46
47
48
49
50
51
<?php $message=urldecode($_GET["message"]); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>操作成功</title> <style type="text/css"> *{margin:0px;padding:0px;} .box{ width:450px; border:1px solid #f0f0f0; background:#FFFFCC; margin:100px auto; padding:20px; font-size:14px; line-height:180%; color:#444; } h2{margin-bottom:10px;} #time{color:#FF0000;} .color2{color:#0099FF;} a.a1:link,a.a1:visited{color:#0099FF;text-decoration:none;} a.a1:hover{color:#FF0000;text-decoration:underline;} </style> </head> <body> <div class="box"> <h2 align="center">操作失败</h2> <p><b>提示:<?php echo $message;?></b></p> <p>系统将在 <span id="time">5</span> 秒钟后自动跳转,如果不想等待,请点击 <a class="a1" href="javascript:history.go(-2);">这里</a> 跳转。</p> </div> </body> </html> <script language="javascript"> function playSec(num) { var time = document.getElementById("time"); time.innerText=num; if(--num >0) { setTimeout("playSec("+num+")",1000); //设置定时器,每一秒调用一次playSec()函数 }else { history.go(-2); //后退两个页面 } } playSec(5); </script>
登录后复制

推荐学习:《PHP视频教程》

以上就是php怎么实现五秒后跳转的详细内容,更多请关注靠谱客其它相关文章!

最后

以上就是时尚嚓茶最近收集整理的关于php怎么实现五秒后跳转的全部内容,更多相关php怎么实现五秒后跳转内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(136)

评论列表共有 0 条评论

立即
投稿
返回
顶部