Home > Backend Development > PHP Tutorial > A small example of preventing repeated submission of forms in php

A small example of preventing repeated submission of forms in php

WBOY
Release: 2016-07-25 08:58:06
Original
1033 people have browsed it
This article introduces a simple example of PHP preventing repeated submission of forms. Friends in need can refer to it.

This section introduces how to use session in php to help prevent repeated submission of forms.

Thinking: Use session to record the number of submissions, and make judgments based on the number to prevent repeated submissions.

Example:

<?php
//防止表单重复提交
//edit by bbs.it-home.org
session_start();
$_SESSION["num"] = 0;
if(isset($_POST["action"] && $_POST["action"]=="post")){
if($_SESSION["num"] == 0){
    echo "提交成功!";
   $_SESSION["num"] = 1;
}else{
   echo "请不要重复提交!";
}
}
?>
Copy after login

The example is a bit simple, just for reference by beginners.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template