How does the php interface determine repeated submissions?

(*-*)浩
Release: 2023-02-27 09:48:02
Original
3682 people have browsed it

PHP uses session judgment to prevent the form from being submitted repeatedly. When the user submits the form, in order to prevent repeated operations, the session is used to judge whether it is the first submission, otherwise it will return to the previous form page.

How does the php interface determine repeated submissions?

The current form page is_submit is set to 0 (Recommended learning: PHP video tutorial)

SESSION_START(); 
$_SESSION['is_submit'] = 0;
<form id="reg" action="post.php" method="post"> 
    <p>用户名:<input type="text" class="input" name="username" id="user"></p> 
    <p>密   码:<input type="password" class="input" name="password" id="pass"></p> 
    <p>E-mail:<input type="text" class="input" name="email" id="email"></p> 
    <p><input type="submit" name="submit" class="btn" value="提交注册"/></p> 
</form>
Copy after login

It is time to submit the form. Set the current 'is_submit to 1. If post.php is refreshed, the else code will be executed.

SESSION_START(); 
if (isset($_POST[&#39;submit&#39;])) { 
    if ($_SESSION[&#39;is_submit&#39;] == &#39;0&#39;) { 
        $_SESSION[&#39;is_submit&#39;] = &#39;1&#39;; 
        echo "代码块,要做的事,代码...<a onclick=&#39;history.go(-1);&#39; href=&#39;javascript:void(0)&#39;>返回</a>"; 
    } else { 
        echo "请不用重复提交<a href=&#39;index.php&#39;>PHP+SESSION防止表单重复提交</a>"; 
    } 
}
Copy after login

The above is the detailed content of How does the php interface determine repeated submissions?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!