thinkphp: Check if session is out of date

Source: Internet
Author: User

1. Create session

1      Public function Index () {2         $sess _time= time(); 3         Session ('name','Andy'); 4         Session ('time_stamp', $sess _time); 5     }

2. Check if session is out of date

1     /**2 * Check if session expires (30 minutes)3      */4      Publicfunction Checksesstime () {5         if(!$_session) {6Header'Content-type:text/html;charset=utf-8');7Die'');8         }9$sess _end_time=time ();//take the current timeTen         //reads the timestamp in the session One         ifC'Session_prefix')){//if the session has a prefix A$sess _time=$_session[c ('Session_prefix')]['Time_stamp']; -}Else{//If the session does not have a prefix -$sess _time=$_session['Time_stamp']; the         } -         //session expires in 30 minutes . -         if($sess _time+ -* -<$sess _end_time) { -SessionNULL); +         } -}

thinkphp: Check if session is out of date

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.