Home > Backend Development > PHP Tutorial > PHP prevents repeated submission by refreshing the page_PHP tutorial

PHP prevents repeated submission by refreshing the page_PHP tutorial

WBOY
Release: 2016-07-21 14:51:33
Original
1260 people have browsed it

As phpers, in the process of developing and learning PHP, we inevitably have to accept and process form data frequently. However, when processing forms, there is always a problem that bothers everyone, the problem of repeated submissions after refreshing the page. How to prevent repeated submissions when refreshing the page?

In fact, we will have many methods in PHP learning. For example, the simplest one is that we can use the method of jumping after the submission is successful. But sometimes, there will be many bottlenecks in this way. For example, if our page has a lot of content that needs to be loaded, especially a lot of dealing with the background, then if the page is jumped and reloaded, it may put pressure on the server. Here we can use another method to prevent repeated submissions by refreshing the page, so that everyone can learn PHP better.

We can use session to solve this problem. We first create a new session and assign it a value. After the first submission, we change the value of the session. When we submit this content for the second time, if it is not our assignment, the passed data will not be processed.
Such as:
session_start();
$_SESSION['num'] = 0;
if(isset($_POST['action'] && $_POST['action']=='submit')){
if($_SESSION['num'] == 0){
echo ''Please try again;'
$_SESSION['num'] = 1;
}else{
echo 'You have already submitted, please do not submit again';
}
}
?>
The front page is not given, I believe everyone knows how to write it before. In fact, there are many ways to prevent repeated submissions by refreshing the page. In the future PHP learning exchanges, more will be listed.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/371779.htmlTechArticleAs phpers, in the process of developing and learning php, we inevitably have to often accept and process form data. However, when processing forms There will always be a problem that bothers everyone. Refreshing the page repeats...
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