濮阳杆衣贸易有限公司

主頁 > 知識(shí)庫 > redis+php實(shí)現(xiàn)微博(一)注冊(cè)與登錄功能詳解

redis+php實(shí)現(xiàn)微博(一)注冊(cè)與登錄功能詳解

熱門標(biāo)簽:智能電話機(jī)器人好公司門薩維 德陽中江如何申請(qǐng)400開頭電話 銅川電話機(jī)器人價(jià)格 沛縣400電話辦理 聊城電話外呼系統(tǒng)公司 AI電話機(jī)器人OEM貼牌 青白江地圖標(biāo)注 江蘇電商外呼系統(tǒng)運(yùn)營商 辦理重慶400電話

本文實(shí)例講述了redis+php實(shí)現(xiàn)微博注冊(cè)與登錄功能。分享給大家供大家參考,具體如下:

(一)、微博功能概況

微博用戶賬號(hào)注冊(cè)

微博用戶登錄

微博發(fā)布

添加微博好友(粉絲)

微博推送

微博冷數(shù)據(jù)寫入mysql數(shù)據(jù)庫

(二)、redis數(shù)據(jù)結(jié)構(gòu)設(shè)計(jì)

這節(jié)分享微博用戶注冊(cè)與登錄:
我們完全采用redis作為數(shù)據(jù)庫來實(shí)現(xiàn)注冊(cè)于登錄
先來看一下redis數(shù)據(jù)結(jié)構(gòu)的設(shè)計(jì):

注冊(cè)用戶表:user

set global:userid

set user:userid:1:username zhangshan

set user:userid:1:password 1212121212

set user:username:zhangshan:userid 1

發(fā)布微博表:post

set post:postid:3:time timestamp

set post:postid:3:userid 5

set post:postid:3:content 測試發(fā)布哈哈哈哈

incr global:postid

set post:postid:$postid

(三)、核心代碼說明

注冊(cè)代碼:

include("function.php");
//用戶表單提交數(shù)據(jù)接收
$username = I('username');
$password = I('password');
$pwd = I('password2');
if(!$username || !$password || !$pwd){
  exit('用戶名密碼不能夠?yàn)榭諂');
}
if($password!=$pwd){
  exit('兩次密碼輸入不一致哦~');
}
//連接redis調(diào)用公用方法
$r = redis_connect();
//判斷用戶是否注冊(cè)過
$info = $r->get("user:username:".$username.":userid");
if($info){
  exit('該用戶已經(jīng)注冊(cè)過');
}
//將用戶數(shù)據(jù)存入redis中
$userid = $r->incr('global:userid');
$r->set("user:userid:".$userid.":username",$username);
$r->set("user:userid:".$userid.":password",$password);
$r->set("user:username:".$username.":userid",$userid);
header("location:home.php");

登錄代碼:

include("function.php");
//如果用戶已經(jīng)登錄調(diào)整到微博列表頁面
if(isLogin()!=false){
  header("location:home.php");
  exit;
}
$username = I('username');
$password = I('password');
if(!$username || !$password){
  exit('數(shù)據(jù)輸入不完整');
}
$r = redis_connect();
$userid = $r->get("user:username:".$username.":userid");
if(!$userid){
  exit('用戶不存在');
}
$password = $r->get("user:userid:".$userid."password:".$password);
if(!password){
  exit('密碼輸入錯(cuò)誤');
}
/**設(shè)置cookie登錄成功**/
setcookie('username',$username);
setcookie('userid',$userid);
header("location:home.php");

function文件代碼:

/*
 *@desc 連接redis操作方法
 */
function redis_connect(){
  $redis = new Redis();
  $redis->connect('127.0.0.1',6379);
  return $redis;
}
/*
 *@desc 接收數(shù)據(jù)方法
 **/
function I($post){
  if(empty($post)){
   return false;
  }
  return trim($_POST[$post]);
}
/**
 *@desc 判斷是否登錄
 ***/
function isLogin(){
  $username = $_COOKIE['username'];
  $userid = $_COOKIE['userid'];
  if(!$username || $userid){
    return false;
  }
  return array('userid'=>$userid,'username'=>$username);
}

說明:代碼寫的可能比較簡單,這里只是闡述實(shí)現(xiàn)原理

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php+redis數(shù)據(jù)庫程序設(shè)計(jì)技巧總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《PHP基本語法入門教程》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

您可能感興趣的文章:
  • PHP實(shí)現(xiàn)發(fā)送微博消息功能完整示例
  • redis+php實(shí)現(xiàn)微博(三)微博列表功能詳解
  • redis+php實(shí)現(xiàn)微博(二)發(fā)布與關(guān)注功能詳解
  • PHP+redis實(shí)現(xiàn)微博的拉模型案例詳解
  • PHP+redis實(shí)現(xiàn)微博的推模型案例分析
  • vue+php實(shí)現(xiàn)的微博留言功能示例
  • php微信分享到朋友圈、QQ、朋友、微博
  • PHP調(diào)用微博接口實(shí)現(xiàn)微博登錄的方法示例
  • php新浪微博登錄接口用法實(shí)例
  • 基于PHP實(shí)現(xiàn)發(fā)微博動(dòng)態(tài)代碼實(shí)例

標(biāo)簽:赤峰 烏魯木齊 山南 鷹潭 南寧 迪慶 濟(jì)寧 三亞

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《redis+php實(shí)現(xiàn)微博(一)注冊(cè)與登錄功能詳解》,本文關(guān)鍵詞  redis+php,實(shí)現(xiàn),微博,一,注冊(cè),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《redis+php實(shí)現(xiàn)微博(一)注冊(cè)與登錄功能詳解》相關(guān)的同類信息!
  • 本頁收集關(guān)于redis+php實(shí)現(xiàn)微博(一)注冊(cè)與登錄功能詳解的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    吉水县| 广州市| 延川县| 曲水县| 钟祥市| 农安县| 新龙县| 鹤峰县| 玛曲县| 健康| 历史| 墨竹工卡县| 奈曼旗| 寿光市| 白朗县| 鲜城| 太康县| 离岛区| 马边| 任丘市| 新津县| 新蔡县| 余干县| 庆城县| 兴安县| 祁门县| 宁明县| 阜宁县| 常宁市| 山阳县| 建德市| 诸暨市| 宁南县| 扶沟县| 运城市| 吐鲁番市| 辽阳市| 乾安县| 广元市| 绥滨县| 鹤壁市|