Home  >  Article  >  Backend Development  >  PHP token usage and verification example [available for testing] [original]

PHP token usage and verification example [available for testing] [original]

不言
不言Original
2018-04-26 15:08:261456browse

This article mainly introduces the use and verification method of php token. It realizes the token verification function by processing the hidden submission field of the form form to prevent the access of illegal source data. Friends in need can refer to this article

The example describes the use and verification of php token. Share it with everyone for your reference, the details are as follows:

1. Brief description of token function

PHP uses token verification to effectively prevent illegal sources Data submission access, increasing the security of data operations

2. Implementation method:

Front desk 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.&#39;#$@%!^*&#39;.time());?>"/>
</form>


The token verification part of background do.php:


<?php
$module = $_POST[&#39;module&#39;];
$timestamp = $_POST[&#39;timestamp&#39;];
$token = md5($module.&#39;#$@%!^*&#39;.$timestamp);
if($token != $_POST[&#39;token&#39;]){
 echo(&#39;非法数据来源&#39;);
 exit();
}
$sec_name=$_POST[&#39;sec_name&#39;];
//PHP数据处理.....
?>

Related recommendations:

Use token to pass parameters in Postman

thinkphp5 WeChat public account token authentication

The above is the detailed content of PHP token usage and verification example [available for testing] [original]. 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