A short piece of code prevents page refreshing, which may not be of much purpose. it is just a reference. Principle
A short piece of code prevents page refreshing, which may not be of much purpose. it is just a reference.
Principle: when a page is accessed, check whether a session exists. If no session exists, create a session and set it to the current time. The program runs down normally. if a session exists, determine the time difference between the session time and the current time. if the interval is less than the specified time, for example, 5 minutes, the program is interrupted and an error message is prompted, if the time in the session is greater than the current time, the time in the session is refreshed and the page is executed normally.
The code is as follows:
Session_start (); // start the session
$ TimeOutLimit = "300"; // you can specify a time interval of five minutes.
If (isset ($ _ SESSION ["timeout"]) {// determines whether a session exists.
If (time ()-$ _ SESSION ["timeout"] <$ timeOutLimit) {// if a session exists and the session interval is less than 5 minutes, die () exit and output a prompt.
Die ("Please do not refresh the current page multiple times ");
} Else {// if no timeout occurs, reset the session time to the current time.
$ _ SESSION ["timeout"] = time ();
}
} Else {
$ _ SESSION ["timeout"] = time (); // if no timeout session exists, the session is created as the current time, which is easy to judge when you access the page next time.
}
// Other page code .....
?>