PHP prevents refresh of sample code for repeated submission pages

Source: Internet
Author: User
Tags php session
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 }?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.