Does thinkphp verify whether a user is logged on?

Source: Internet
Author: User
Does thinkphp verify whether a user is logged on? How did you verify it? Is it verified once in every Action? Or write it in a public function for calling?


Reply to discussion (solution)

Generally, it is called.

However, I am using this method to save the cookie after logging on. The php file or a specific location is used to verify whether the cookie exists.

Generally, it is called.

However, I am using this method to save the cookie after logging on. The php file or a specific location is used to verify whether the cookie exists.
Well, this is acceptable. I am in trouble. In common functions, I add user verification methods to determine whether to call user verification methods by judging the values of a and m. However, I added a verification code to the logon interface. when I called the verification code, the verification code was rejected. Find a more convenient method.

A public class can be written for inheritance.

Generally, 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");    }  }}

The code may be wrong,

Generally, 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");    }  }}

The code may be wrong,
Thank you! this is feasible. I just tried it. I didn't expect that the verification code actually called the action under a model. The code has a small error. "_" should be replaced with "/".

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.