PHP token usage and Validation sample "Test Available" [Original]

Source: Internet
Author: User
This article mainly introduces PHP token use and verification method, through the form form hidden submit field processing to implement token verification function, to prevent access to illegal source data, the need for friends can refer to the next

This article describes the use and validation of PHP tokens. Share to everyone for your reference, as follows:

First, token function brief

PHP uses token validation to effectively prevent unauthorized data submission access and increase the security of data operations

Second, the realization method:

Foreground form form:


<form action= "do.php" method= "POST" ><?php $module =mt_rand (100000,999999);? > <input type= "text" name= "Sec_name" value= ""/> <input type= "hidden" name= "module" value= "<?php echo $ module;? > "/> <input type=" hidden "name=" timestamp "value=" <?php Echo time ();? > "/> <input type=" hidden "name=" token "value=" <?php Echo MD5 ($module. ' #$@%!^* '. Time ());? > "/></form>


Token verification section of background do.php:


<?php$module = $_post[' module ']; $timestamp = $_post[' timestamp '); $token = MD5 ($module. ' #$@%!^* '. $timestamp); if ($token! = $_post[' token ') {echo (' illegal data source '); exit ();} $sec _name=$_post[' sec_name '];//php data processing ...? >

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.