php阻止页面后退的方法分享_PHP

WBOY
Release: 2016-06-01 11:55:58
Original
961 people have browsed it

例如:现在有1,2,3。3页。希望用户一开始访问第一页,然后点“下一步”就看到“第二页”,然后在进入“第三页”之前,用户不能
后退。就让1和2作为同一页。留个标记在session里,这样:
1and2.php
复制代码 代码如下:
session_start();
if (isset($_GET['p2'])) {
  $_SESSION['enteredPage2'] = true;
}
if (isset($_SESSION['enteredPage2'])) {
  //输出页面2.在页面2里,包含到页面3的链接如下
  echo "This is page 2. Page3这时候后退不到P1的~";
} else {
  //输出页面1,包含到页面2的链接如下
  echo "This is page 1. Page2";
}
?>

下面是3.php,作用是表示用户已经访问完P2了,要再允许用户访问P1
复制代码 代码如下:
session_start();
unset($_SESSION['enteredPage2']);
?>

以上例子中,页1和页2都是1and2.php生成的临时页面。当用户的浏览器要读这个地址,你输出页2就是页2,不用担心用户
会回到页1去。这个是浏览器无关的最根本的解决方法。

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!