The example of this article describes the Create method and token verification in thinkphp. Share to everyone for your reference, specific as follows:
Thinkphp's Create method and token authentication are mainly related to the security of the form.
The code is as follows:
<?php
//This class is automatically generated by the system, only for test purposes
class Indexaction extends action{public
function Index () {
$this-> Display ();
}
General users in the site to complete the information added modification ... But there was a surprise that the user's Web page was saved as local, and then a lot of the data was simulated in this, and then ... Keep refreshing to write in my database, also the hidden table in the ID to change
//Originally in the process can be judged superior source, if the superior address is equal to the address of my site, I will write it, if not my site, I will prohibit its writing ... The superior source can be simulated
//create () automatically to obtain relevant data; Automatic token verification; Complete automatic mapping, AutoFill, automatic verification (three automatic) Creation success returns an array, or false; Adds a hidden item hidden item encryption method MD5
// Token authentication can be set, and encryption methods can also be set token_no=>true;
function Add () {
$user =new Model (' user ');
if ($vo = $user->create ()) {
//success This method is a method of success, it will give the corresponding jump page, jump time, as well as the success of information prompts, this file in the default public common file
//dump ($VO);
echo $user->username;
echo $user->password;
Dump ($user);
$this->success (' instantiation model succeeded ');
}
else{
//error is the way to fail, in which the execution failure code does not go backwards
$this->error ($user->geterror ());//geterror () Specifically used to display verbose error messages
}}
?>
The template file is as follows:
<form action= "__url__/add" method= "POST" >
<input type= "text" name= "username"/> <input "type="
Password "name=" password "/> <input type=" hidden "
id=" 2 "/> <input type=" Submit "value="
submitted "/>< C5/></form>
I hope this article will help you with the PHP program design based on thinkphp framework.