PHP has been developing for a long time and many users are familiar with PHP. Here I will share my personal understanding and discuss it with you. When we are doing a website, we often get bored with some texts. Sometimes, the user does not know whether the submission is successful due to network conditions or other reasons, and the same form will be submitted again, which leads to repeated submission of PHP forms.
There is a simple way to avoid repeated submission of the same form. First, define a session variable to save the Submission serial number of a PHP form. Here I define it as "$ userLastAction ". Add a hidden variable to the form and set the value
- $userLastAction+1:
- <input type=Hidden name=lastAction value=<? =$userLastAction+1 ?>>
Finally, determine whether the PHP form has been submitted before processing and submission.
- If ($ lastAction>$ UserLastAction ){
- $ UserLastAction ++; // Add 1 to the serial number
- // Process form data
- }
- ?>
The main principle of this technique is that users are not allowed to submit again after rollback. That is to say, it is not allowed to modify and submit again after rollback. However, the irrigation method of Ctrl-C/Ctrl-V cannot be avoided. Backfill of downloaded files: When downloading software, we often see the number of downloads of this software, which makes it easy for the website administrator to analyze the popularity of the software. The implementation principle is: the unique identifier and number of software downloads are stored in the backend database. When users download the software, they first update the number of downloads of the corresponding software, that is, the number of downloads is increased by 1, then, go to the downloaded file to officially start the download. See the following implementation code:
First create a data table download (MySql at the backend)
- The download table contains the following two fields:
- The unique identifier of the downloaded object.
- Downnum downloads. The default value is 0.
Implementation
Assume that the file name has been extracted from the database: The description file name is five-stroke; the download file name is wbzx.zip; the id value is 2. The generated hyperlink code is:
- <A Href="Download. php? Filename=wbzx.zip & id = 2">Five strokes</A>
The following code downloads. php processes the total number of downloads and locates the downloaded files based on the transferred file name.
- // Code for connecting to the Mysql database
- $Res=Mysql_query("Update download setDownnum= (Downnum + 1) whereId='$ Id'", $ Db );
- Header ("location: $ filename ");
- ?>