Home > Article > Backend Development > A small example of preventing repeated submission of forms in php
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. |