Home  >  Article  >  Backend Development  >  A simple example of PHP preventing post from repeatedly submitting data_PHP Tutorial

A simple example of PHP preventing post from repeatedly submitting data_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:28:50878browse

During an interview in a certain empire, I came up with this question: How to deal with duplicate questions in post submissions. Later I communicated with @nuanyang and he said to record the time. I didn’t understand. What I wanted was to use session to record it on the form page. Then submit the page for judgment. If they are equal, it will be regarded as successful and the session will be cleared. But there is a question. What if the form page is HTML? What should I do? How about setting up a PHP verification page? A function similar to the verification code. There are others. It says to use the header to set the expiration time...but I haven't tried it. The following is what I wrote in php, and it has been tested and works.

Copy code The code is as follows:

//Open session
session_start();

//If there is a submission identifier
if(isset($_GET['action']) && $_GET['action'] === 'save'){

//If there is a session and it is the same as the passed value, it is considered submitted
if(isset($_SESSION['__open_auth']) && isset($_POST['auth']) && $_SESSION['__open_auth '] == $_POST['auth']){
print_r($_POST);
$_SESSION['__open_auth'] = null;//Clear
} else {

//Get started
header("location: post.php");
}
exit();
}

//Authorization
$auth = $_SESSION['__open_auth'] = time();

?>








< ul>
        

  •                                                                                                                                                                            ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, "text" name="userName">



  •                                                                                                                time(); ?>










  • http://www.bkjia.com/PHPjc/780484.htmlwww.bkjia.com

    truehttp: //www.bkjia.com/PHPjc/780484.htmlTechArticleI was asked this question during an interview in a certain empire: How to deal with repeated questions in post submissions, and later I talked to @nuanyang During the communication, he said to record the time, but I didn’t understand. What I wanted was to use session to record the time on the form page...
    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