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.