Php 会话过期后如何停止转到下一页?
在测验任务中,当我刷新页面时,我已经完成了为每个页面设置的时间 1分钟后过期。但是,如果单击“下一步”,1分钟后没有刷新页面,它将进入下一个测验页面。我可以阻止它进入下一页。 这是我的密码Php 会话过期后如何停止转到下一页?,php,session,redirect,Php,Session,Redirect,在测验任务中,当我刷新页面时,我已经完成了为每个页面设置的时间 1分钟后过期。但是,如果单击“下一步”,1分钟后没有刷新页面,它将进入下一个测验页面。我可以阻止它进入下一页。 这是我的密码 <html> <head> <style> #user { color:blue; font-size:16px; } #pass { color:blue; font-size:16px; } </style> </head> &
<html>
<head>
<style>
#user
{
color:blue;
font-size:16px;
}
#pass
{
color:blue;
font-size:16px;
}
</style>
</head>
<body>
<table>
<form action="quizpage2.php" method="post">
<tr>
<td><div id="user">Username:</div></td></br>
<td><input type="text" name="user"></td>
</tr>
<tr>
<td><div id="pass">Password:</div></td>
<td><input type="text" name="pass"></td>
</tr>
<tr>
<td><input type="submit" value="submit"></td>
</tr>
</form>
</table>
</body>
</html>
page2
session_start();
$AB=$_POST["user"];
$CD=$_POST["pass"];
$_SESSION["new"]=$AB;
$EF=array("paul", "andrew", "steven" ,"don");
$GH=array(123, 456, 789, 000);
if(($AB==$EF[0])&&($CD==$GH[0]))
{
$_SESSION["new"]=$EF[0];
$_SESSION["start"]=time();
$_SESSION["expire"]=$_SESSION["start"]+(1*60);
echo "<script> alert('login successfull')</script>";
echo "<script>window.location.assign('quizpage3.php')</script>";
}
?>
page3-
<?php
session_start();
if(!isset($_SESSION["new"]))
{
echo"<p align='center';>Please login Again";
echo"<a href='quizpage1.php'>Click here</a></p>";
//header("location:quizpage1.php");
}
else
{
$now=time();
if($now>$_SESSION['expire'])
{
session_destroy();
echo"<p align='centre;'>your session is expired!<a href='quizpage1.php'>Login Here</a></p>";
echo"<span style='float:right;'><a href='logoutpage.php'>Logout</a></span>";
}
else
{
echo"<html>";
echo"<head>";
echo"<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js'></script>";
echo"<script>
$(document).ready(function() {
window.history.forward(1);
});
</script>";
echo"<style>
#sun
{
background-color:lightblue;
width:60%;
}
</style>";
echo"</head>";
echo"<body>";
echo"<form action='quizpage4.php' method='post'>";
echo"<div id='sun'>";
echo"<tr>";
echo"<td>Which of the following part of the Sun is visible by human?</td></br>";
echo"<td><input type='radio' name='sun' value='Photosphere'>Photosphere</td>.</br>";
echo"<td><input type='radio' name='sun' value='Corona'>Corona</td>.</br>";
echo"<td><input type='radio' name='sun' value='Chromosphere'>Chromosphere</td>.</br>";
echo"<td><input type='radio' name='sun' value='Core'>Core</td>.</br>";
echo"</tr>";
echo"<tr>";
echo"<td><input type='submit' value='Nextpage'></td>";
echo"</tr>";
echo"</div>";
echo"</form>";
echo"</table>";
echo"</body>";
echo"</html>";
}
}
?>
enter code here
Logoutpage-
<?php
session_start();
session_destroy();
header("location:quizpage1.php");
?>de here
#使用者
{
颜色:蓝色;
字体大小:16px;
}
#通过
{
颜色:蓝色;
字体大小:16px;
}
用户名:
密码:
第2页
会话_start();
$AB=$_POST[“用户”];
$CD=$_POST[“pass”];
$\u会话[“新建”]=$AB;
$EF=数组(“保罗”、“安德鲁”、“史蒂文”、“唐”);
$GH=阵列(123456789000);
如果($AB=$EF[0])&($CD==$GH[0]))
{
$_会话[“新建”]=$EF[0];
$\会话[“开始”]=time();
$\会话[“过期”]=$\会话[“开始”]+(1*60);
回显“警报('login successfull')”;
echo“window.location.assign('quizpage3.php')”;
}
?>
第3页-
您已使用会话时间到期
重新登录
如果页面刷新,则重新加载整个调用并检查您的时间到期
$now=time();
if($now>$_SESSION['expire'])
{
session_destroy();
echo"<p align='centre;'>your session is expired!<a href='quizpage1.php'>Login Here</a></p>";
echo"<span style='float:right;'><a href='logoutpage.php'>Logout</a></span>";
}
错误在这里,您的表单操作在未选中会话的情况下单击按钮并访问下一页
因此,您需要删除表单操作
如操作=”“
并添加下一步按钮的名称
如
echo"<td><input type='submit' value='Nextpage' name='submit'></td>";
echo"<td><input type='submit' value='Nextpage' name='submit'></td>";
if(isset($_POST['submit']) && !empty($_POST['submit']))
{
echo "<script>window.location.assign('quizpage4.php')</script>";
}
$now=time();
if($now>$_SESSION['expire'])
{
//echo 1;exit;
session_destroy();
echo"<p align='centre;'>your session is expired!<a href='quizpage1.php'>Login Here</a></p>";
echo"<span style='float:right;'><a href='logoutpage.php'>Logout</a></span>";
}