thinkphp User Registration Login Message Complete instance, thinkphp User Registration _php Tutorial

Source: Internet
Author: User

thinkphp User Registration Login Message Complete instance, thinkphp user Registration


In this paper, we describe the functions of thinkphp implementation including user registration, login and message, and we need to note that the D method is used when instantiating a user class in the presence of a user model .

UserActiion.class.php page:

<?phpclass Useraction extends Action{public function add () {$user = D ("user"); $user->create (); $result = $user Add (), if ($result) {$this->assign ("Jumpurl", "__app__/index/index"); $this->success (' Registration successful! ');} Else{//echo $user->geterror (), $this->assign ("Jumpurl", "__app__/user/register"), $this->error ($user GetError ());}} Public Function Register () {$this->display ();} Public Function Login () {$this->display ();} Public Function Checklogin () {$username = $_post[' username '); $passwd = $_post[' passwd ']; $user = D ("user");//$User Where (' id=8 ')->find (); Here's where statement to note, if it is the other field must be followed by a single quotation mark $userinfo = $user->where ("username = ' $username '")- >find (), if (!empty ($userinfo)) {if ($userinfo [' passwd '] = = $passwd) {cookie::set (' userid ', $userinfo [' ID '],time () + 3600*24); Cookie::set (' username ', $username, Time () +3600*24); Cookie::set (' Lastlogintime ', Time (), Time () +3600*24), $this->assign ("Jumpurl", "__app__/index/index"); $this- >success (' Landing success! ');} else{$this->assign ("Jumpurl", "__app__/user/login "); $this->error (' Password error, please re-enter! ');}} else{$this->assign ("Jumpurl", "__app__/user/login"); $this->error (' username does not exist! ');}} Public Function Loginout () {Cookie::d elete (' username '); Cookies::d elete (' Lastlogintime '), $this->assign ("Jumpurl", "__app__/index/index"), $this->success (' You have successfully exited, Welcome to your next login!  ');}}

IndexAction.class.php page:

<?php//This class is automatically generated by the system for testing purposes class Indexaction extends Action{public function Insert () {$content = new Contentmodel (); $re Sult = $content->create (), if (! $result) {$this->assign ("Jumpurl", "__url__/index"), $this->error ($content- >geterror ());//If the creation fails, indicating that the validation did not pass, the output error message}else{//validation passed, other operations $content->userid=cookie::get (' UserID '); $content- >add (); $this->assign ("Jumpurl", "__url__/index"); $this->success (' Add success! ');}}  Data query Operation Public Function index () {$content = new Contentmodel (); $list = $content->findall (); The user's Cookie$username = cookie::get (' username '); $lastlogintime = Cookie::get (' lastlogintime '); $this->assign ('    List ', $list); $this->assign (' title ', ' My Home '), $this->assign (' username ', $username); $this->assign (' Lastlogintime ', $  Lastlogintime); $this->display (); }//delete operation public Function Delete () {$content = new Contentmodel (); $id = $_get[' id '];if ($content->where ("id= $id") Delete ()) {$this->assign ("Jumpurl", "__url__/index"), $this->success (' Delete succeeded! ');} Else{$this->assign ("Jumpurl", "__url__/index"); $this->error (' Delete failed! ');}} Edit Operation Public Function edit () {$content = new Contentmodel (); $id = $_get[' id '];if ($id! = ') {//$data = $content->select ( $id) $data = $content->where ("id= $id")->select (), if (!empty ($data)) {$this->assign (' data ', $data);} Else{echo "Data is empty! ";}} $this->assign (' title ', ' edit Page '); $this->display ();} Update operation public Function Update () {$content = new Contentmodel ();//Direct use of Create (), automatically will help you to data value/* $content->create (); $ Content->save (); Save modified data based on conditions echo "Update data successfully!" *///uses POST to update $id = $_post[' id '];if ($id! = ') {$data [' id '] = $id; $data [' title '] = $_post[' title ']; $data [' Content '] = $_post[' content '];if ($content->save ($data))//Save modified data by condition {$this->assign ("Jumpurl", "__url__/ Index "); $this->success (' Update data Success! ');} else{$this->assign ("Jumpurl", "__url__/index"); $this->success (' Update data failed! ');}} Else{echo "failed to save data! ";}}}?  >

ContentModel.class.php page:

<?phpclass Contentmodel extends model{/** automatic verification * Array (validation fields, validation rules, error prompts, validation conditions, additional rules, validation time) */protected $_validate = Array ( Array (' title ', ' Require ', ' title must be filled in! '), array (' content ', ' require ', ' contents must be filled in! '), */* * AutoFill * Array (fill field, fill content, fill condition, additional rule) */ Protected $_auto = Array (Array (' addtime ', ' time ', 1, ' function '),); >

UserModel.class.php page:

<?phpclass Usermodel extends model{protected $_validate = Array (Array (' username ', ' ', ' account name already exists! ', 0, ' unique ', 1),);  }? >


It should be noted here that the use of automatic authentication when instantiated with $user = D ("user") instead of $user = m ("user"), with M this method will be an error, D function is used to instantiate the MODEL,M function user instantiation of a file without a model.

Success.html page:

 
  
 
  Information Tips
 
  
  
Information Tips

{$message}
Return to the specified page after 2 seconds!
If your browser is unable to jump, click here.


PHP User Registration Login message problem!!

That depends on what you want, PHP is a language that can be combined with scripting, you can write PHP code on your Good registration page, and of course your files will be saved as PHP files.
But in your case, since the registration page is in the DW, we just need to select the Action property of the form form to put your PHP file location inside as


So your message board content will be submitted to the 1.php page and your page format is HTML we can be in 1. The PHP page uses post to get your form submitted, but first you have to name the commit variable, for example, we write a text box.

The property of name in this is the name of the variable we get
We use $_post[' text ' to get the content you submitted is as simple as that.

thinkphp User Registration issues

If it's empty, you should just submit the data in the form.
You are now primarily positioning the error: is the key of the form data corresponding to the key of the database table? Is the thinkphp's token check turned on?

http://www.bkjia.com/PHPjc/844131.html www.bkjia.com true http://www.bkjia.com/PHPjc/844131.html techarticle thinkphp User Registration Login Message Complete instance, thinkphp user registration This article in the form of an example of thinkphp implementation including the user's registration, login and message functions, which need a large ...

  • 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.