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

A small example of preventing repeated submission of forms in php

WBOY
WBOYOriginal
2016-07-25 08:58:061017browse
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 "请不要重复提交!";
}
}
?>

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



Statement:
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