PHP prevents refresh of the sample code on the repeated submission page, and php sample code. PHP prevents refresh of the sample code of the repeated submission page. php prevents refresh of the sample code of the repeated submission page as phper. during The PHP development and learning process, it is inevitable that PHP should frequently prevent refresh of the sample code on the repeatedly submitted page, and php Sample code
PHP prevents refresh of sample code for repeated submission pages
As a phper, we will inevitably accept and process form data frequently in the process of developing and learning php. However, there will always be a problem when processing forms, which bothers everyone, refresh the page for repeated submission. How can we prevent repeated page refreshes?
PHP prevents Refresh and repeated submission. by repeatedly refreshing (Refresh or Reload) the form submission page, you can submit the form content repeatedly. you can avoid this by using PHP sessions, which are saved on the server side, after changing the value of the Session variable in the PHP process, it is stored on the server end. the new value is obtained when the variable is accessed next time. therefore, you can use a Session variable to record the number of times a form is submitted. if it is greater than 1, data in the form will not be processed.
Core code
Reference content is as follows:
if (isset($_POST['action']) && $_POST['action'] == 'submitted') { session_start(); if (isset($_SESSION['submit_time']) && $_SESSION['submit_time']==0){ print ''; print_r($_POST); print 'Please try again'; 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']; ?> <?php } ?>
Using PHP prevents refresh and repeated page submission sample code as phper. it is inevitable that php is frequently used during development and learning...