Field design:
#Set the login account:
set user:1:account zhangsan
set user:2:account lisi
#Set username:
set user:1:name Zhang San
set user:2:name Li Si
#Set email:
set user:1:email [email protected]
set user:2:email [email protected]
#set password:
set user:1:passwd 123456
set user:2:passwd 666666
#In order to find a specific person (including name and password, etc.) according to the unique account number and unique email address, then set:
set zhangsan:uid 1
set lisi: uid 2
set [email protected]:uid 1
set [email protected]:uid 2
Add 1 to global:uid for each registered user
incr global:uid
php code example:
login.php
<?php //session is stored in redis. If there is no configuration in php.ini, it can be configured in the php code: ini_set('session.save_handler', 'redis'); ini_set('session.save_path', 'tcp://127.0.0.1:6379'); session_start(); //Already logged in, jump to the home page if($_SESSION['uid']){echo 'hh'; header('Location:./index.php'); } if(!$_POST['account'] || !$_POST['passwd']){ die('Please enter the account password completely'); } //connect to redis $redis = new Redis(); $redis->connect('127.0.0.1',6379); $uid = $redis->get($_POST['account'].':uid'); $passwd = $redis->get('user:'.$uid.':passwd'); if(!$uid || $passwd!=$_POST['passwd']){ die('Account or password error'); }else{ echo 'Login successful'; } $_SESSION['uid']=$uid;
Note: You can configure session storage redis in php.ini
session.save_handler = redis
session.save_path = "tcp://127.0.0.1:6379"
register.php<?php
if(!$_POST['account'] || !$_POST['passwd'] || !$_POST['passwd2']){ die('Please enter the registration information completely'); } if($_POST['passwd'] != $_POST['passwd2']){ die('Two times of password input are inconsistent'); } if(strlen($_POST['passwd'])<6){ die('password cannot be less than 6 digits'); } //connect to redis database $redis = new Redis(); $redis->connect('127.0.0.1',6379); //Check if the username has been registered if($redis->get($_POST['account'].':uid')){ die('The account has been registered'); } //Increase global:uid by 1 each time a user is registered $uid = $redis->incr('global:uid'); $redis->set('user:'.$uid.':account',$_POST['account']); $redis->set('user:'.$uid.':passwd',$_POST['passwd']); $redis->set($_POST['account'].':uid',$uid); ~