婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

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

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

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

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

(一)、微博功能概況

微博用戶賬號注冊

微博用戶登錄

微博發(fā)布

添加微博好友(粉絲)

微博推送

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

(二)、redis數(shù)據(jù)結構設計

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

注冊用戶表: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

(三)、核心代碼說明

注冊代碼:

include("function.php");
//用戶表單提交數(shù)據(jù)接收
$username = I('username');
$password = I('password');
$pwd = I('password2');
if(!$username || !$password || !$pwd){
  exit('用戶名密碼不能夠為空~');
}
if($password!=$pwd){
  exit('兩次密碼輸入不一致哦~');
}
//連接redis調用公用方法
$r = redis_connect();
//判斷用戶是否注冊過
$info = $r->get("user:username:".$username.":userid");
if($info){
  exit('該用戶已經注冊過');
}
//將用戶數(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");
//如果用戶已經登錄調整到微博列表頁面
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('密碼輸入錯誤');
}
/**設置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);
}

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

更多關于PHP相關內容感興趣的讀者可查看本站專題:《php+redis數(shù)據(jù)庫程序設計技巧總結》、《php面向對象程序設計入門教程》、《PHP基本語法入門教程》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》

希望本文所述對大家PHP程序設計有所幫助。

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

標簽:赤峰 烏魯木齊 山南 鷹潭 南寧 迪慶 濟寧 三亞

巨人網絡通訊聲明:本文標題《redis+php實現(xiàn)微博(一)注冊與登錄功能詳解》,本文關鍵詞  redis+php,實現(xiàn),微博,一,注冊,;如發(fā)現(xiàn)本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統(tǒng)采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《redis+php實現(xiàn)微博(一)注冊與登錄功能詳解》相關的同類信息!
  • 本頁收集關于redis+php實現(xiàn)微博(一)注冊與登錄功能詳解的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 泽库县| 南皮县| 全南县| 汉沽区| 会宁县| 襄樊市| 侯马市| 南投县| 柯坪县| 海林市| 布拖县| 阿拉善盟| 和田县| 监利县| 本溪市| 蛟河市| 龙山县| 南乐县| 酒泉市| 垦利县| 永康市| 汽车| 镇坪县| 嘉禾县| 肥西县| 长沙市| 乌兰浩特市| 麻城市| 株洲县| 邓州市| 东乌珠穆沁旗| 北海市| 云浮市| 望江县| 广平县| 南澳县| 察雅县| 滦平县| 丰城市| 道真| 乳源|