<?php require("redis.php"); $username = $_POST['username']; $pass = $_POST['password']; //根据注册时存储的以用户名为键的字符类型中查找用户id $id = $redis->get("username:".$username); if(!empty($id)){ $password = $redis->hget("user:".$id,"password"); if(md5($pass) == $password){ $auth = md5(time().$username.rand()); $redis->set("auth:".$auth,$id); setcookie("auth",$auth,time()+86400); header("location:list.php"); } } ?> <form action="" method="post"> 用户名:<input type="text"/><br> 密码:<input type="password"><br> <input type="submit" value="登录"/> </form>
删除
del.php
<?php require("redis.php"); $uid = $_GET['id']; //echo $uid; $username = $redis->hget("user:".$id,"username"); $a=$redis->del("user:".$uid); $redis->del("username:".$username); $redis->lrem("uid",$uid); //var_dump($a); header("location:list.php");
编辑界面
mod.php
<?php require("redis.php"); $uid = $_GET['id']; $data=$redis->hgetall("user:".$uid); ?> <form action="doedit.php" method="post"> <input type="hidden" value="<?php echo $data['uid'];?>"> 用户名:<input type="text" value="<?php echo $data['username'];?>"><br> 年龄:<input type="text" value="<?php echo $data['age'];?>"><br> <input type="submit" value="提交"> <input type="reset" value="重填"> </form>
编辑功能
doedit.php
<?php require('redis.php'); $uid = $_POST['uid']; $username = $_POST['username']; $age = $_POST['age']; $a=$redis->hmset("user:".$uid,array("username"=>$username,"age"=>$age)); if($a){ header("location:list.php"); }else{ header("location:mod.php?id=".$uid); }
加关注
addfans.php
<?php //关注功能,建议用集合实现,因为集合元素唯一,并且可以容易求出两个用户粉丝之间交集与差集,进而进行好友推荐功能 $id = $_GET['id']; $uid = $_GET['uid']; require("redis.php"); $redis->sadd("user:".$uid.":following",$id); $redis->sadd("user:".$id.":followers",$uid); header("location:list.php");
更多关于PHP相关内容感兴趣的读者可查看本站专题:《php+redis数据库程序设计技巧总结》、《PHP扩展开发教程》、《php+mysql数据库操作入门教程》、《php+mysqli数据库程序设计技巧总结》、《php面向对象程序设计入门教程》、《PHP网络编程技巧总结》及《php常见数据库操作技巧汇总》