PHP prevents refresh of the sample code on the repeated submission page. php sample code _ PHP Tutorial

Source: Internet
Author: User
Tags php sample code
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...

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.