Home >Backend Development >PHP Tutorial >PHP sample code to prevent refreshing of repeated submission pages, php sample code_PHP tutorial

PHP sample code to prevent refreshing of repeated submission pages, php sample code_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:05:081120browse

PHP sample code to prevent refreshing of duplicate submission pages, php sample code

PHP sample code to prevent refreshing of duplicate submission pages

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, such as refreshing the page and submitting repeatedly. How to prevent repeated submissions when refreshing the page?

PHP prevents refresh and repeated submission. By continuously refreshing (Refresh or Reload) the form submission page, the form content can be submitted repeatedly. You can use PHP's Session to avoid this. The Session is saved on the server side and the Session variable is changed during the PHP process. After the value is saved on the server side, the next time you access this variable, you will get the newly assigned value. Therefore, you can use a Session variable to record the number of form submissions. When it is greater than 1, the data in the form will no longer be processed.

Core Code

The following is the quotation:

if (isset($_POST['action']) && $_POST['action'] == 'submitted') { 
session_start(); 
if (isset($_SESSION['submit_time']) && $_SESSION['submit_time']==0){ 
print '<pre class="brush:php;toolbar:false">'; 
print_r($_POST); 
print '<a href="'. $_SERVER['PHP_SELF'] .'">Please try again</a>'; 
print '
'; $_SESSION['submit_time']=1; echo $_SESSION['submit_time']; unset($_SESSION['submit_time']); } else { print '
'; 
print_r($_POST); 
echo "However you have submitted"; 
print '
'; } } else { session_start() or dir("session is not started"); $_SESSION['submit_time']= 0; // isset($_SESSION['submit_time']) or die ("session var is not created"); // echo $_SESSION['submit_time']; ?>
Name:
Email:
Beer:

<?php } ?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1070278.htmlTechArticleSample code for PHP to prevent refreshing of repeated submission pages, php sample code PHP to prevent refreshing of repeated submission pages as phper , in the process of developing and learning PHP, we inevitably have to often...
Statement:
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