How PHP keeps the login state

Source: Internet
Author: User
Keywords Php
    1. A variety of websites often have similar "keep 30 days automatic login" option, how do they do the time to save the login status?

    2. Why my website, in the local time, as long as the browser opens, the account will remain logged in, but after uploading to the server, as long as there is no operation or refresh the page, the login status will be invalid (I use the TP framework, session (' Admin_uid ') record login status)?

This is my login verification code,

validateLogin();//代表登录验证操作if($result){//代表验证成功 括号内进行的是存session以及页面跳转操作}//要保存指定时间的登录状态,这里应该怎么写?

Reply content:

    1. A variety of websites often have similar "keep 30 days automatic login" option, how do they do the time to save the login status?

    2. Why my website, in the local time, as long as the browser opens, the account will remain logged in, but after uploading to the server, as long as there is no operation or refresh the page, the login status will be invalid (I use the TP framework, session (' Admin_uid ') record login status)?

This is my login verification code,

validateLogin();//代表登录验证操作if($result){//代表验证成功 括号内进行的是存session以及页面跳转操作}//要保存指定时间的登录状态,这里应该怎么写?

You set up session in fact will automatically expire after a certain period of time, but the automatic landing (keep logged on) the implementation of this function is cookie to achieve, you need to put your account password through encryption means to enter cookie , and if the site session does not exist, and then take out cookie Information decryption, in-house do a landing on the good, so that the realization of automatic landing, you can also cookie set the validity period, the final effect can be achieved ~

The browser settings cookie expiration time is set to 30 days so that you can stay logged in.

Http://www.thinkphp.cn/topic/4484.html
Originally wanted to write about. Find out on the internet there are ready-made ... Let me give you a reference.

Typically, login expiration is cookie,session these two expire and can be set to a valid time by a cookie to achieve
First, when the user first logs on, the user information is encrypted, and then the cookie is stored on the client, valid for 30 days,
Then, when the user nth access, if the status is not logged in, then read the user information from the cookie, decrypt, verify the user information, if passed, it automatically log in

session_id with Data inventory

  • 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.