thinkphp Verify that the user is logged on?

Source: Internet
Author: User
How are we going to verify this? Validate once in every action? Or is it written in a public function called?


Reply to discussion (solution)

It's usually called.

But that's what I'm doing now. Log in and save the cookie with the PHP file or a specific location to verify the existence of this cookie

It's usually called.

But that's what I'm doing now. Log in and save the cookie with the PHP file or a specific location to verify the existence of this cookie
Well, that's OK. Just feel the trouble. In the common general function, I add the method of validating the user, by judging the values of A and m, whether to invoke the method of validating the user. But because I added a verification code in the login interface, a call, the verification code will not come out. Want to find a more convenient way.

Can write a public class inheritance

In general, I do this:

Class Baseaction extends action{  function _initialize () {     if (!in_array (model_name. ') _'. Action_name,explode (', ', ' public/login,public/loginon,public/verify ')) {     if (!isset ($_session[' login])!! Empty (Session (' login ')))            $this->redirect ("/login");}}}  

Maybe the code is wrong, huh?

In general, I do this:

Class Baseaction extends action{  function _initialize () {     if (!in_array (model_name. ') _'. Action_name,explode (', ', ' public/login,public/loginon,public/verify ')) {     if (!isset ($_session[' login])!! Empty (Session (' login ')))            $this->redirect ("/login");}}}  

Maybe the code is wrong, huh?
Kazakhstan, this is feasible, just tried, and did not think that the verification code is actually called a model under the action. The code is a little bit wrong, "_" should be replaced by "/".
  • 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.