Home  >  Article  >  Backend Development  >  How to implement php token verification

How to implement php token verification

藏色散人
藏色散人Original
2021-09-26 10:05:533775browse

php token verification implementation method: 1. Create a front-end form; 2. Set the token verification part of the back-end "do.php", with code such as "if($token != $_POST['token'] ){...}".

How to implement php token verification

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer.

How to implement php token verification?

php token usage and verification examples [available for testing]

The examples in this article describe the use and verification of php tokens. 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 source data from being submitted for access and increase the security of data operations

2. Implementation method:

Foreground 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>

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数据处理.....
?>

Recommended learning: "PHP Video tutorial

The above is the detailed content of How to implement php token verification. 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