Home  >  Article  >  Backend Development  >  A simple way to implement user login in php

A simple way to implement user login in php

墨辰丷
墨辰丷Original
2018-05-24 10:36:111754browse

This article mainly introduces relevant information on simple examples of user login in php. Friends who need it can refer to

Simple example of user login in php

Foreword:

The last part to be completed recently is to manage the data submitted by users. As for management, it must be the administrator's business, which must involve logging in and verifying account permissions. , whether the account has expired, etc.

Required knowledge

session is indeed a very important thing. And I encountered that the session could not cross pages, so I modified the session.use_trans_sid = 0 value of PHP.ini to 1.

Detailed implementation

My background design is relatively simple. You only need to enter a password. This password is of course saved on the server and can be changed. So you only need to add two variables to the session, flag and time.

First, use flag to determine whether the administrator has successfully logged in, and use time to determine whether the login has timed out. After submitting the password, if it is correct, the flag will be assigned a value of 1, and the time will be assigned the current time. Each time you enter a new page or perform an operation, these two variables will be judged. First, judge whether the flag value is 1. If it is not unique, it will directly prompt that you are not logged in and destroy the session. If it is 1, then judge the current time -$_SESSION(' time') is less than 600 (10 minutes). If it is greater, the login timeout will be prompted and the session will be destroyed; if it is less, the operation will be allowed and the time variable value will be updated to the current value.

Part of the code

check_pw.php


  点此跳转

list_all.php(Part )

 600){
    echo "登陆超时";
    echo '点此登陆';
    session_destroy();
    exit();
  }else{
  $_SESSION['time'] = time();
  }
}else{
  echo "未登陆,无权访问!";
  echo '点此登陆';
  session_destroy();
  exit();
}
?>

The above is the entire content of this article, I hope it will be helpful to everyone's study.


Related recommendations:

php mysql develops the simplest online question bank and online question making system

PHPDifferentiate enterprise WeChat browser | Ordinary WeChat browser | Other browsers

##PHPtwo Dimensional array deduplication based on a certain element

The above is the detailed content of A simple way to implement user login in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn