64. 雇员管理系统
2015-11-21 17:11
218 查看
项目开发阶段
1.需求分析
创建表:
不到数据库验证:
到数据库验证:
1.需求分析
创建表:
不到数据库验证:
login.php <html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8"/> </head> <body> <h1>管理员登陆系统</h1> <form action="loginProcess.php" method="post"> <table> <tr> <td>用户id</td><td><input type="text" name="id"/></td> </tr> <tr> <td>密码</td><td><input type="password" name="password"/></td> </tr> <tr> <td><input type="submit" value="用户登陆"/></td> <td><input type="reset" value="重新填写"/></td> </tr> </table> </form> <?php if(!empty($_GET['errno'])){ //接收errno $errno = $_GET['errno']; if($errno == 1){ echo "<br/><font color='red'>你的用户名或者密码错误</font>"; } } ?> </body> </html>
loginProcess.php <?php $id = $_POST['id']; $password = $_POST['password']; if($id == '100' && $password =='123'){ //合法,跳转到empManage.php header('Location:empManage.php'); //跳转后要退出,最好退出,退出进程,一个请求对应一个进程 exit(); }else{ //非法,跳转回去 header('Location:login.php?errno=1');//带点信息给login.php exit(); }
empManage.php <?php header('Content-Type:text/html;charset=utf-8'); echo "登陆成功<br/>"; echo "<br/><a href='login.php'>返回重新登陆</a>"; ?>
到数据库验证:
login.php <html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8"/> </head> <body> <h1>管理员登陆系统</h1> <form action="loginProcess.php" method="post"> <table> <tr> <td>用户id</td><td><input type="text" name="id"/></td> </tr> <tr> <td>密码</td><td><input type="password" name="password"/></td> </tr> <tr> <td><input type="submit" value="用户登陆"/></td> <td><input type="reset" value="重新填写"/></td> </tr> </table> </form> <?php if(!empty($_GET['errno'])){ //接收errno $errno = $_GET['errno']; if($errno == 1){ echo "<br/><font color='red'>你的用户名或者密码错误</font>"; } } ?> </body> </html>
loginProcess.php <?php $id = $_POST['id']; $password = $_POST['password']; //到数据库去验证 //1.得到连接 $link = mysql_connect('localhost','root','123456'); if(!$link){ die('连接失败' . mysql_error()); } //2.设置访问数据库的编码形式 mysql_query('set names utf8',$link) or die('set names error' . mysql_error()); //3.选择数据库 mysql_select_db('test',$link) or die(mysql_error()); //4.发送sql语句,验证 //防止sql注入攻击 //改变验证逻辑 //$sql = "select * from admin where id='{$id}' and password='{$password}'"; $sql = "select password from admin where id='{$id}' and password='{$password}'"; //1.通过输入的id来获取数据库中的密码,再和输入的密码进行比对 $res = mysql_query($sql,$link); if($row = mysql_fetch_assoc($res)){ //查询到了 //2.取出数据库的密码 if($row['password'] == $password){ //说明合法 header('Location:empManage.php'); exit(); } } header('Location:login.php?errno=1'); exit(); //关闭资源 mysql_free_result($res); mysql_close($link); /*if($id == '100' && $password =='123'){ //合法,跳转到empManage.php header('Location:empManage.php'); //跳转后要退出,最好退出,退出进程,一个请求对应一个进程 exit(); }else{ //非法,跳转回去 header('Location:login.php?errno=1');//带点信息给login.php exit(); }*/
empManage.php <html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8"/> </head> <body> <h1>主页面</h1> <a href="">管理用户</a> <a href="">添加用户</a> <a href="">查询用户</a> <a href="">退出系统</a> </body> </html> <?php header('Content-Type:text/html;charset=utf-8'); echo "登陆成功<br/>"; echo "<br/><a href='login.php'>返回重新登陆</a>"; ?>
相关文章推荐
- 1036、跟奥巴马一起编程
- 话题8 基本for循环与加强型for循环
- 【bzoj1052】【HAOI2007】【覆盖问题】【贪心】
- 最大期望(EM)算法
- css案例学习之class执行的顺序
- tcp协议中mss的理解
- ThinkPHP 中实现 Rewrite 模式
- C语言模拟实现memset.memcmp函数
- HDU 2122(最小生成树模板)
- LaTeX文档插入png图片
- 认识Java
- tcp的精髓:滑动窗口
- VIM文本替换命令
- 关于使用MD5加密方法
- pySerial 学习笔记-安装与测试
- Windows XP硬盘安装Ubuntu 12.04
- Spring浅析之注解之一@Service、@Component、@Controller、@Repository
- gradle 构建java工程
- iOS 6.0中UIViewController被弃用的一些方法
- c语言:给十个整数比较大小