PHP implementation prevents form recurrence Submission (token-based authentication)

Source: Internet
Author: User
This article mainly introduces the implementation of PHP to prevent the recurrence of forms, combined with examples of PHP-based token verification to prevent the form of repeated submission of the relevant operation skills, very simple and practical, the need for friends can refer to the next

The example in this article describes the PHP implementation to prevent forms from repeating the submission feature. Share to everyone for your reference, as follows:

There are a number of ways to prevent forms from repeating submissions, so let's introduce how PHP can effectively prevent forms from repeating submissions today.

The code is very simple

I believe that we are very clever to share a small demo, we can learn from:

Specific code:

<?php/** September 29, 2016 08:09:13*/session_start (); Header ("content-type:text/html;charset=utf-8"); function set_ Token () {$_session[' token '] = MD5 (Microtime (TRUE));}  function Valid_token () {$return = $_request[' token '] = = = $_session[' token ']? True:false;  Set_token (); return $return;} Generates a tokenif (!isset ($_session[' token ') "If token is empty) | | $_session[' token ']== ') {Set_token ();} if (Isset ($_post[' web ')) {if (!valid_token ()) {echo "token error, please do not repeat the submission!)  ";  }else{Echo ' successfully submitted, Value: '. $_post[' web '; }}else{?><! DOCTYPE html>

The above is the whole content of this article, thank you for reading. Read more about topic.alibabacloud.com!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.