PHP Determines whether the user has logged in (jumps to a different page or performs a different action) _php instance

Source: Internet
Author: User
Tags curl setcookie

1.

2.

<if condition= "$GLOBALS [' userinfo '] [' user_id '] GT 0" >
<span class= "help_wz" ><a href= "{$ think.config.vip_url}/member/user_pwd/"style=" color: #404958; " > Find login Password </a></span>
<else/>
<span class= "help_wz" ><a href= "/login/findpwd" style= "COLOR: #404958;" > Find login password </a></span>
</if>

3. Setting global variables in the background and querying user information

Public Function UserInfo ($user _id) {//query System Information $system =array (' CmdId ' => ' system ', ' Token ' => ' wap ', ' postdetails ' =
>json_encode (Array ()));
Sending an interface request via Curl Post mode $curl =new Curlcontroller ();
$strs = $curl->sendcurl ($system);
$GLOBALS [' System ']= $strs [' acctdetails '];
if (Empty ($user _id)) {return false;} setcookie ("Login_uid", $user _id, time () + 3600, "/", C (' Cookie_url ')); Setcookie ("Rdun"), $this->authcode ($user _id. "," .
Time (), "ENCODE"), time () + 3600, "/", C (' Cookie_url '));; $data =array (' CmdId ' => ' individual ', ' Token ' =>session (' Token '), ' postdetails ' =>json_encode (' User_
Id ' => $user _id));
Sending an interface request via Curl Post mode $curl =new Curlcontroller ();
$str = $curl->sendcurl ($data);
$GLOBALS [' userinfo ']= $str [' acctdetails '];
$newtoken =unserialize ($str [' acctdetails '] [' token ']);
$oldtoken =unserialize (Session (' token ')); if (!empty (Session (' token ')) &&!empty ($str [' acctdetails '] [' token ']) {//user not to if ($newtoken [' user_id ']!== $
newtoken[' user_id '] {session (' token ', null);Session (' user_id ', null);
Header (' Location:/login/login ');
return false; //token does not $newtoken [' time ']!== $oldtoken [' time ']} {session (' token ', null); session (' user_id ', null); Header ('
Location:/login/login ');
return false;
//timeout cannot be done in this, because the value of the session is unchanged, if the user has been operating, and only once, then there will be problems} return true; }

The above is a small set to the introduction of PHP to determine whether the user has logged in (jump to different pages or perform different actions), I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.