Home > Backend Development > PHP Tutorial > How to prevent the page from going back in PHP_PHP Tutorial

How to prevent the page from going back in PHP_PHP Tutorial

WBOY
Release: 2016-07-13 10:25:07
Original
1317 people have browsed it

For example: Now there are 1, 2, 3. 3 pages. It is hoped that the user will visit the first page at the beginning, then click "Next" to see the "second page", and then the user cannot
go back before entering the "third page". Let 1 and 2 be the same page. Leave a mark in the session, like this:
1and2.php

Copy the code The code is as follows:

session_start();
if (isset($_GET['p2'])) {
$_SESSION['enteredPage2'] = true;
}
if (isset($ _SESSION['enteredPage2'])) {
//Output page 2. In page 2, the link to page 3 is as follows
echo "This is page 2. Page3At this time, we cannot go back to P1~";
} else {
//Output page 1, including the link to page 2 as follows
echo "This is page 1. ;a href="?p2=">Page2";
}
?>

The following is 3.php, which indicates that the user has completed the visit P2, you need to allow users to access P1
Copy code The code is as follows:

session_start( );
unset($_SESSION['enteredPage2']);
?>

In the above example, page 1 and page 2 are both temporary pages generated by 1and2.php. When the user's browser wants to read this address, the output page 2 is page 2. Don't worry that the user
will return to page 1. This is the most fundamental solution that is browser-independent.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825224.htmlTechArticleFor example: Now there are 1, 2, 3. 3 pages. It is hoped that the user will visit the first page at the beginning, then click "Next" to see the "Second Page", and then before entering the "Third Page", the user cannot continue...
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