Analysis of the example of Create method and token verification in thinkphp _php example

Source: Internet
Author: User

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.

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.