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 ...? >