Yii MVC user registration and User Logon (5)

Source: Internet
Author: User

5. Analyze the session and cookie, and distinguish the session and cookie before and after;

Remember logon status

In this way, you do not need to enter the user name and password again when you log on to the website again.

It is the cookie of the browser that remembers the status.


Form creation:

                                <tr>                                    <td align="right">                                        <?php echo $form->checkBox($user_login, 'rememberMe'); ?>                                    </td>                                    <td>                                        <?php echo $form->labelEx($user_login, 'rememberMe'); ?>                                    </td>                                </tr>
Modify model:


View cookie and session information results:


Major User Logon:

/** Log out of the system */function actionlogout () {// Delete the session information // yii: APP ()-> session-> clear (); // Delete the sessiion variable information in the memory // yii: APP ()-> session-> destroy (); // Delete the server's session file // Delete the session and cookie together. Otherwise, you cannot exit yii: APP ()-> User-> logout (); $ this-> redirect ('/');}
In this case, there will be a problem:

You can set the session prefix in the background.

{Public function Init () {// custom background default controller $ this-> defaultcontroller = "Index "; // this method is called when the module is being created // you may place code here to customize the module or the application // import the module-level models and components $ this-> setimport (Array ('houtai. models. * ', 'houtai. components. * ',); // set the session name prefix information for the background logon administrator yii: APP ()-> setcomponents (Array ('user' => array ('statekeypr Efix '=> 'houtai', 'loginurl' =>'./index. php? R = houtai/manager/login ',)));}

Figure:



stateKeyPrefix
How are the parameters?

In this way:


Yii MVC user registration and User Logon (5)

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.