PHP checks whether the user has logged on (jump to different pages or perform different actions), and php jumps

Source: Internet
Author: User

PHP checks whether the user has logged on (jump to different pages or perform different actions), and php jumps

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; "> retrieve logon password </a> </span> <else/> <span class =" help_wz "> <a href ="/Login/FindPwd "style =" color: #404958; "> retrieve the logon password </a> </span> </if>

3. Set global variables in the background and query user information

Public function UserInfo ($ user_id) {// query system information $ System = array ('regionid' => 'system', 'Token' => 'wap ', 'postdetails '=> json_encode (array (); // send the Interface request $ curl = new CurlController () through the curl post method (); $ 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 ('regionid' => 'individual', 'Token' => session ('Token '), 'postdetails' => json_encode (array ('user _ id' => $ user_id ,))); // send an Interface request through the curl post method $ 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']) {// the user does not have an if ($ newtoken ['user _ id']! = $ Newtoken ['user _ id']) {session ('Token', null); session ('user _ id', null); header ('location: /Login '); return false;} // if ($ newtoken ['time']! = $ Oldtoken ['time']) {session ('Token', null); session ('user _ id', null); header ('location: /Login '); return false;} // timeout cannot be performed here because the value of the session to be saved remains the same. If the user logs on only once, then the problem will occur} return true ;}

The above section describes how to use PHP to determine whether a user has logged on (jump to different pages or perform different actions). I hope it will help you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.