php的登陆系统
来源:互联网 发布:周金涛2019买点知乎 编辑:程序博客网 时间:2024/06/06 06:31
参考文章http://blog.csdn.net/qazcxh/article/details/45726911
php的学习一直处于简单的一两个文件之内,今天看到了一个比较多文件的学习文章,于是就照着它动手敲了一遍了,感觉还可以。
第一部分当然就是登陆的界面了:
index.html
<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>登陆注册修改密码系统主页</title> <style type="text/css"> form{ text-align:center; } </style></head><body><!-- 表单 --> <form action="enter.php" method="post" onsubmit="return enter()"> 用户名<input type="text" name="username" id="username"><br/>密码<input type="password" name="password" id="password"><br/><input type="submit" value="登陆"><input type="button" value="注册" onclick="register();"> </form> <script type="text/javascript"> //检测数据是否正确,从而判断是否提交表单数据 function enter(){ var username=document.getElementById("username").value; var password=document.getElementById("password").value; var regex=/^[/s]+$/; if(regex.test(username)||username.length==0){ alert("用户名格式不对"); return false; } if(regex.test(password)||password.length==0){ alert("密码格式不对"); return false; } return true; } //转到注册页面 function register(){ window.location.href="register.html"; } </script></body></html>enter.php:
<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>登陆系统的后台执行过程</title></head><body> <?php session_start();//开启session //获取表单中input的name中的数据 $username=$_REQUEST["username"]; $password=$_REQUEST["password"]; //连接服务器 $con=mysql_connect("localhost","root","root"); if(!$con){ die('数据库连接失败'.mysql_error()); } //选择数据库 mysql_select_db("user_info",$con); $dbusername=null; $dbpassword=null; //查找当前输入的用户名 $result=mysql_query("select * from user_info where username='{$username}' and isdelete=0;"); while($row=mysql_fetch_array($result)){ $dbusername=$row["username"]; $dbpassword=$row["password"]; } //如果不存在,返回index.html //密码不正确,也是返回index.html if(is_null($dbusername)){ ?> <script type="text/javascript"> alert("用户名不存在"); window.location.href="index.html"; </script> <?php } else { if($dbpassword!=$password){ ?> <script type="text/javascript"> alert("密码错误"); window.location.href="index.html"; </script> <?php } else{ $_SESSION["username"]=$username; //给session一个随机值,防止直接在地址栏内输入wecome的地址 $_SESSION["code"]=mt_rand(0,100000); ?> <script type="text/javascript"> window.location.href="wecome.php"; </script> <?php } } mysql_close($con); ?></body></html>
wecome.php:
<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>欢迎登陆界面</title></head><body> <?php session_start();//打开session //判断是否设置了session【“code”】 if(isset($_SESSION["code"])){ ?> 欢迎登陆<?php echo "${_SESSION["username"]}"; ?><br/> 您的ip:<?php echo "{$_SERVER['REMOTE_ADDR']}"; ?> <br/> 您的语言: <?php echo "${_SERVER['HTTP_ACCEPT_LANGUAGE']}"; ?> <br/> 浏览器版本: <?php echo "${_SERVER['HTTP_USER_AGENT']}"; ?> <a href="exit.php">退出登陆</a> <?php }else { ?> <script type="text/javascript"> alert("退出登陆"); window.location.href="exit.php"; </script> <?php } ?> <br/> <a href="alter_password.html">修改密码</a></body></html>
alter_password.html:
<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>修改密码</title> <style type="text/css"> form{ text-align:center; } </style></head><body> <?php session_start(); ?> <form action="alter_password.php" method="post" onsubmit="return alter()"> 用户名<input type="text" name="username" id="username" /><br/>旧密码<input type="password" name="oldpassword" id="oldpassword" />新密码<input type="password" name="newpassword" id="newpassword" /><br/>确认新密码<input type="password" name="assertpassword" id="assertpassword"/><br/><input type="submit" value="修改密码" onclick="return alter()"> </form> <script type="text/javascript"> document.getElementById("username").value="<?php echo "${_SESSION["username"]}";?>"; </script> <script type="text/javascript"> //判断是否传数据过form的action function alter(){ var username=document.getElementById("username").value; var oldpassword=document.getElementById("oldpassword").value; var newpassword=document.getElementById("newpassword").value; var assertpassword=document.getElementById("assertpassword").value; var regex=/^[/s]+$/; if(regex.test(username)||username.length==0){ alert("用户格式不对"); return false; } if(regex.test(oldpassword)||oldpassword.length==0){ alert("密码格式不对"); return false; } if(regex.test(newpassword)||newpassword.length==0){ alert("新密码格式不对"); return false; } if(assertpassword!=newpassword||assertpassword==0){ alert("两次密码输入不一致"); return false; } return true; } </script></body></html>
alter_password.php:
<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>正在修改密码</title></head><body> <?php session_start();//打开session //提取input标签的一系列数据 $username = $_REQUEST["username"]; $oldpassword = $_REQUEST["oldpassword"]; $newpassword = $_REQUEST["newpassword"]; //连接服务器 $con = mysql_connect("localhost","root","root"); if(!$con){ die('数据库连接失败'.mysql_error()); } //选择数据库 mysql_select_db("user_info",$con); $dbusername = null; $dbpassword = null; //查找当前名字的数据 $result = mysql_query("select * from user_info where username='{$username}' and isdelete=0;"); while($row=mysql_fetch_array($result)){ $dbusername = $row["username"]; $dbpassword = $row["password"]; } //判断是否存在 if(is_null($dbusername)){ ?> <script type="text/javascript"> alert("用户名不存在"); window.location.href="alter_password.html"; </script> <?php } //判断旧密码和当前所用密码是否相同 if($oldpassword!=$dbpassword){ ?> <script type="text/javascript"> alert("密码错误"); window.location.href="alter_password.html"; </script> <?php } mysql_query("update user_info set password='{$newpassword}' where username='{$username}'") or die("存入数据库失败".mysql_error()); mysql_close($con); ?> <script type="text/javascript"> alert("密码修改成功"); window.location.href="index.html"; </script></body></html>
register.html:
<!DOCTYPE html><html><head><meta charset="utf-8"><title>注册系统</title><style type="text/css"> form{ text-align:center; }</style></head><body> <!-- 表单 --> <form action="register.php" method="post" name="form_register" onsubmit="return check()"> 用户名<input type="text" name="username" id="username"><br/> 密码<input type="password" name="password" id="password"><br/> 确认密码<input type="password" name="assertpassword" id="assertpassword"><br/> <input type="submit" value="注册"> </form> <script type="text/javascript"> //检查输入的东西是否符合,不符合不传数据过register.php function check(){ var username=document.getElementById("username").value; var password=document.getElementById("password").value; var assertpassword=document.getElementById("assertpassword").value; var regex=/^[/s]+$/; if(regex.test(username)||username.length==0){ alert("用户名格式不对"); return false; } if(regex.text(password)||password.length==0){ alert("密码格式不对"); return false; } if(password!=assertpassword){ alert("两次密码输入不一致"); return false; } } </script></body></html>
register.php:
<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>注册用户</title></head><body> <?php session_start();//打开session //获取传过来的数值 $username=$_REQUEST["username"]; $password=$_REQUEST["password"]; //连接服务器 $con=mysql_connect("localhost","root","root"); if(!$con){ die('数据库连接失败'.mysql_error()); } //选择数据库 mysql_select_db("user_info",$con); $dbusername=null; $dbpassword=null; //查询当前名字的数据是否存在 $result=mysql_query("select * from user_info where username='{$username}'and isdelete=0"); while($row=mysql_fetch_array($result)){ $dbusername=$row["username"]; $dbpassword=$row["password"]; } //如果存在 if(is_null($dbusername)){ ?> <script type="text/javascript"> alert("用户名已存在"); window.location.href="register.html"; </script> <?php } mysql_query("insert into user_info (username,password)values('{$username}','{$password}')") or die("存入数据库失败".mysql_error()); mysql_close($con); ?> <script type="text/javascript"> alert("注册成功"); window.location.href="index.html"; </script></body></html>
退出登陆时exit.php:
<!DOCTYPE html><html><head> <meta charset="utf-8"></head><body> <?php session_start();//打开session session_destroy();//将之前的session数据全部删除掉 ?> <script type="text/javascript"> window.location.href="index.html";//跳转到index.html </script></body></html>
9.mysql数据库搭建部分
0 0
- php的登陆系统
- 用php实现正方教务系统的模拟登陆
- 【php】2、学生管理系统-登陆进去
- 【php】6、学生管理系统-登陆进去
- php模拟登陆正方管理系统
- php模拟登陆青果教务系统
- php实现模拟登陆带验证码并且重定向的教务处系统
- 项目实战篇-餐馆管理系统—MFC,PHP,MySql:2.登陆功能的实现
- 系统自动登陆的命令
- 简单登陆系统的开发
- 一个简单的登陆系统
- 简单的SSO登陆系统
- php 加xml创建小型客户关系管理登陆系统
- php模拟登陆校园教务网络管理系统
- PHP的curl带验证码模拟登陆学校的教务系统(验证码已被自动识别,不需要输入)
- 纯基于PHP的单点登陆
- 纯基于PHP的单点登陆
- 纯基于PHP的单点登陆
- [LeetCode]--292. Nim Game
- [LeetCode]413.Arithmetic Slices
- List集合遍历详解
- OpenGL学习(二):画Square
- 两个质数之积
- php的登陆系统
- Spring之Email<封装了常用的四种发送Email的方法(TEXT,HTML,IMG,FILE)>
- 用Scala在IDEA中开发WordCount
- 高通LCD之MDP code简析
- SpringMVC3.0+MyIbatis3.0(分页示例)
- java序列化的作用
- [时钟同步]Can't create ASM instance on node2 during running root.sh on node2 due to Time Syc
- Tomcat的安装与配置还有问题解决
- 软考--原码、补码、反码