码迷,mamicode.com
首页 > Web开发 > 详细

php redis实例

时间:2015-04-09 06:33:40      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:用户名   密码   

test.php



<?php

$redis = new Redis();

$redis->connect(‘127.0.0.1‘,6379);


?>



===========================

add.php


<form method=‘POST‘ action=‘reg.php‘>

 用户名:<input type=‘text‘ name=‘username‘/>

 密码:<input type=‘password‘ name=‘pwd‘/>

 年龄:<input type=‘text‘ name=‘age‘/>

 <input type=‘submit‘ value=‘提交‘>

 <input type=‘reset‘ value=‘重新填写‘>

</form>


==============================

reg.php



<?php

require(‘test.php‘);

$username = $_POST[‘username‘];

$pwd = $_POST[‘pwd‘];

$age = $_POST[‘age‘];

$uid = $redis->incr(‘userId‘);

$redis->hmset("user:".$uid,array(‘uid‘=>$uid, ‘username‘=>$username, ‘pwd‘=>$pwd, "age"=>$age));

//print_r($redis->keys("*"))

    header("location:list.php");

?>




=============


list.php


<?php

require(‘test.php‘);

$count = $redis->get(‘userId‘);

//echo $count;

for ($i=1; $i<=$count; $i++) {

// print_r($redis->hGetAll("user:".$i));

$data[] = $redis->hGetAll("user:".$i);

}


$data = array_filter($data);//过滤掉空数组(删除造成的)


?>


<a href=‘add.php‘>注册</a>

<table border=‘1‘>

<tr>

<th>姓名</th>

<th>密码</th>

<th>年龄</th>

<th>操作</th>

</tr>

<?php

foreach ($data as $v) {

?>

<tr>

<td><?php echo $v[‘username‘];?></td>

<td><?php echo $v[‘pwd‘];?></td>

<td><?php echo $v[‘age‘];?></td>

<td><a href="del.php?id=<?php echo $v[‘uid‘]; ?>">删除</a><a href="modify.php?id=<?php echo $v[‘uid‘]; ?>">修改</a></td>

</tr>

<?php }

?>


    

</table>





=========================

del.php



<?php

require(‘test.php‘);

$uid = $_REQUEST[‘id‘];

//$uid=‘10000‘;

$num = $redis->del("user:".$uid);

//echo $num;exit();

if ($num == 0) {

echo "删除失败";

} else {

header("location:list.php");

}

?>


php redis实例

标签:用户名   密码   

原文地址:http://seetobest.blog.51cto.com/1351397/1630216

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!