Home  >  Article  >  Backend Development  >  How does the php interface determine repeated submissions?

How does the php interface determine repeated submissions?

(*-*)浩
(*-*)浩Original
2019-10-18 11:38:523678browse

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>

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>"; 
    } 
}

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!

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
Previous article:Where is php used?Next article:Where is php used?