We can avoid this by using the PHP Session. The Session is stored on the server. After the value of the Session variable is changed during the PHP process, it is stored on the server. The next time you access this variable, new
We can avoid this by using the PHP Session. The Session is stored on the server. After the value of the Session variable is changed during the PHP process, it is stored on the server. The next time you access this variable, new
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 }?>