How to jump after five seconds in php

藏色散人
Release: 2023-03-14 16:48:01
Original
9697 people have browsed it

php method to achieve jump after five seconds: 1. Create a success.php operation success page; 2. Create an error.php operation failure page; 3. Use "playSec(5);" to achieve five seconds It will jump after a few seconds.

How to jump after five seconds in php

#The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.

How to jump after five seconds in php?

PHP will automatically jump to a page after 5 seconds:

history.go(-2); //javaScript code, go back two pages.

setTimeout("playSec(" num ")",1000); //JavaScript code, timer, call playSec() function after one second.

  • success.php Operation success page

  • error.php Operation failure page

1. success.php Operation success page

<?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>
Copy after login

2, error.php Operation failure page

<?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>
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to jump after five seconds in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template