一天一篇之php学习篇2
2014-01-11 09:39
363 查看
今天简单的写了下php后台登录,所使用的方法为 $_post,$_SESSION,及数据库连接,刚开始对session的定义不是很清楚,查看了帮助文档,里面的定义为'当前脚本可用 SESSION 变量的数组',解释的很抽象,其实session就是客户端与服务端会话,当session_start()运行的时候,在服务器产生了一个session文件,随之也产生了唯一一个对应的session id,$_SESSION['client']客户端注册一把钥匙来打开服务端的锁。
以下代码检测可用
数据库片段
以下代码检测可用
<?php if(isset($_POST["submit"])) { $username = $_POST['user'];//用户名 $pwd = $_POST['pwd'];//密码 /*数据库连接方法*/ $hostname = 'localhost'; $user = "root"; $password = "root"; $link = mysql_connect($hostname,$user,$password); //mysql_query("set names utf-8"); mysql_select_db('cms',$link);//选择库名 $query = "select * from admin where username = '$username' and password = '$pwd'"; $rs = mysql_query($query);//执行查询 if(mysql_num_rows($rs) == 1) { $_SESSION['pwd'] = $_POST['pwd'];//数据匹配 $_SERVER['admin'] = session_id(); echo "<script>alert('登录成功');window.location = 'admin_index.php';</script>"; } } ?> <?php /*退出系统*/ if(!empty($_GET['tj'])) { session_start(); session_destroy(); echo "<script>alert('退出成功');window.location = 'admin.php';</script>"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>cms管理系统</title> <style> body{background:#ccc;} input{display:block; margin:10px 0;} </style> </head> <body> <form action="" method="post" name="frm" id="frm"> <label>用户名:<input type="text" size="20" maxlength="20" name="user" /></label> <label>密 码:<input type="password" name="pwd" /></label> <input type="submit" value="登录" name="submit" /> </form> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script> <script> jQuery.fn.center = function () { this.css("position","absolute"); this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px"); this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px"); return this; } $('#frm').center(); </script> </body> </html>
数据库片段
相关文章推荐
- 一天一篇之php学习篇6
- 一天一篇之php学习篇2_1
- 一天一篇之php学习篇3
- 一天一篇之php学习篇7
- 一天一篇之php学习篇1
- 一天一篇之php学习篇4
- 一天一篇之php学习篇5
- php下删除一篇文章生成的多个静态页面
- PHP计算当月第一天和最后一天
- PHP 取前一天或后一天、一个月时间
- A HOWTO on Optimizing PHP(如何优化PHP的一篇文章)
- 一篇关于介绍php的几个user 认证相关的几个包
- PHP获得指定日期所在月的第一天和最后一天
- php倒计时 时分秒 (每个月1号到最后一天)
- php时间的操作,前一天,后一天时间的获取
- 用了几乎一天时间配置了apach+php+mysql
- 每日工作 第一篇(一天一篇)
- [转]榨干 PHP,不得不转的一篇PHP使用技巧!
- PHP获取一个月的第一天和最后一天
- 榨干 PHP,不得不转的一篇PHP使用技巧!