Analysis of the create method and token verification instance in thinkPHP

Source: Internet
Author: User
This article mainly introduces the create method and token verification in thinkPHP, analyzes the related techniques of adding form security by using the create method and token verification in thinkPHP in the form of a simple example, and provides detailed comments to the code, for more information about ThinkPHP, see ThinkPHP.

This example describes the create method and token verification in thinkPHP. We will share this with you for your reference. The details are as follows:

ThinkPHP's create method and token verification mainly involve form security.

The code is as follows:

<? Php // this class is automatically generated by the system and is for test purposes only. class IndexAction extends Action {public function index () {$ this-> display ();} // general users add and modify information on the website ...... However, in an accident, the user's webpage was saved as a local file, and a lot of data was simulated here, and then ...... Constantly update and write data to my database, and change the id in the hidden table to // you can determine the parent source during the processing. if the parent address is equal to the address of my website, I will write it. if it is not my website, I will prohibit it from writing ...... The upper-level source can be simulated // create () to automatically obtain relevant data; automatic token verification; automatic ING, automatic filling, and automatic verification (three major Automatic) if it is successfully created, an array is returned; otherwise, false is returned. a hidden item encryption method md5 // token verification can be set. the encryption method can also be set TOKEN_NO => true; function add () {$ user = new Model ('user'); if ($ vo = $ user-> create ()) {// success: This method is a method for successful execution. It provides the corresponding jump page, jump time, and success message, this file is stored in the default Public file // dump ($ vo); echo $ user-> username; echo $ user-> password; dump ($ user ); $ this-> success ('Model instantiated successfully');} else {// error is the method of execution failure In this method, the failed code will not continue to $ this-> error ($ user-> getError (); // getError () used to display detailed error information }}?>

The template file is as follows:

 

I hope this article will help you design PHP programs based on the 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.