PHP+MySQL登录注册,完整版,详细注释
纯手写打造。
下载地址:http://download.csdn.net/detail/qq_33599520/9779970
项目结构:

下面是代码:
<!DOCTYPE html>
<html lang="cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>后台登陆</title>
<link href="css/login.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="js/login.js"></script>
</head>
<body>
<div class="login">
<div class="message">大数据的事件智能抓取和画像后台登陆</div>
<div id="darkbannerwrap"></div>
<form name="login" action="php/login.php" method="post" onsubmit="return check()">
<input name="name" id="name" placeholder="请输入登录帐号" type="text" required="required" maxlength="16">
<hr class="hr15">
<input name="password" id="password" placeholder="请输入登录密码" type="password" required="required" maxlength="16">
<hr class="hr15">
<input value="登录" style="width:100%;" type="submit" name="submit">
<a href="result.html">注册</a>
<a href="#">忘记密码</a>
<hr class="hr20">
</form>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>后台注册</title>
<link href="css/result.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="js/result.js"></script>
</head>
<body>
<div class="login">
<div class="message">大数据的事件智能抓取和画像后台注册</div>
<div id="darkbannerwrap"></div>
<form name="result" action="php/result.php" method="post" onsubmit="return check()">
<input name="name" id="name" placeholder="请输入帐号" type="text" required="required" maxlength="16">
<hr class="hr15">
<input name="password" id="password" placeholder="请输入密码" type="password" required="required" maxlength="16">
<hr class="hr15">
<input name="pwd" id="pwd" placeholder="请再次输入密码" type="password" required="required" maxlength="16">
<hr class="hr15">
<input value="注册" style="width:100%;" type="submit" name="submit">
<a href="login.html">返回登录</a>
<a href="#">忘记密码</a>
<hr class="hr20">
</form>
</div>
</body>
</html>
function $(id) {
return document.getElementById(id);
}
function check() {
var password = $("password").value;
if(password == "") {
alert("密码不能为空");
$("password").focus();
return false;
}
if(password.length < 6) {
alert("密码长度必须为6-16位");
$("password").focus();
return false;
}
}
function $(id) {
return document.getElementById(id);
}
function check() {
var password = $("password").value;
var pwd = $("pwd").value;
if(password == "") {
alert("密码不能为空");
$("password").focus();
return false;
}
if(password.length < 6) {
alert("密码长度必须为6-16位");
$("password").focus();
return false;
}
if(pwd != password) {
alert("您两次输入的密码不一致!");
$("pwd").focus();
return false;
}
}
*{
font: 13px/1.5 '微软雅黑', Verdana, Helvetica, Arial, sans-serif;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-box-sizing: border-box;
padding:0;
margin:0;
list-style:none;
box-sizing: border-box;
}
body,html{
height:100%;
overflow:hidden;
}
body{
background:url(../images/web_login_bg.jpg) no-repeat center;
background-size: cover;
}
a{
color:#27A9E3;
text-decoration:none;
cursor:pointer;
}
.login{
margin: 150px auto 0 auto;
min-height: 420px;
max-width: 420px;
padding: 40px;
background-color: #ffffff;
margin-left: auto;
margin-right: auto;
border-radius: 4px;
/* overflow-x: hidden; */
box-sizing: border-box;
}
a.logo{
display: block;
height: 58px;
width: 167px;
margin: 0 auto 30px auto;
background-size: 167px 42px;
}
.message {
margin: 10px 0 0 -58px;
padding: 18px 10px 18px 60px;
background: #27A9E3;
position: relative;
color: #fff;
font-size: 16px;
}
#darkbannerwrap {
background: url(../images/aiwrap.png);
width: 18px;
height: 10px;
margin: 0 0 20px -58px;
position: relative;
}
input[type=text],
input[type=file],
input[type=password],
input[type=email], select {
border: 1px solid #DCDEE0;
vertical-align: middle;
border-radius: 3px;
height: 50px;
padding: 0px 16px;
font-size: 14px;
color: #555555;
outline:none;
width:100%;
}
input[type=text]:focus,
input[type=file]:focus,
input[type=password]:focus,
input[type=email]:focus, select:focus {
border: 1px solid #27A9E3;
}
input[type=submit],
input[type=button]{
display: inline-block;
vertical-align: middle;
padding: 12px 24px;
margin: 0px;
font-size: 18px;
line-height: 24px;
text-align: center;
white-space: nowrap;
vertical-align: middle;
cursor: pointer;
color: #ffffff;
background-color: #27A9E3;
border-radius: 3px;
border: none;
-webkit-appearance: none;
outline:none;
width:100%;
}
hr.hr15 {
height: 15px;
border: none;
margin: 0px;
padding: 0px;
width: 100%;
}
hr.hr20 {
height: 20px;
border: none;
margin: 0px;
padding: 0px;
width: 100%;
}
.copyright{
font-size:14px;
color:rgba(255,255,255,0.85);
display:block;
position:absolute;
bottom:15px;
right:15px;
}
*{
font: 13px/1.5 '微软雅黑', Verdana, Helvetica, Arial, sans-serif;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-box-sizing: border-box;
padding:0;
margin:0;
list-style:none;
box-sizing: border-box;
}
body,html{
height:100%;
overflow:hidden;
}
body{
background:url(../images/web_result_bg.jpg) no-repeat center;
background-size: cover;
}
a{
color:#27A9E3;
text-decoration:none;
cursor:pointer;
}
.login{
margin: 150px auto 0 auto;
min-height: 420px;
max-width: 420px;
padding: 40px;
background-color: #ffffff;
margin-left: auto;
margin-right: auto;
border-radius: 4px;
/* overflow-x: hidden; */
box-sizing: border-box;
}
a.logo{
display: block;
height: 58px;
width: 167px;
margin: 0 auto 30px auto;
background-size: 167px 42px;
}
.message {
margin: 10px 0 0 -58px;
padding: 18px 10px 18px 60px;
background: #27A9E3;
position: relative;
color: #fff;
font-size: 16px;
}
#darkbannerwrap {
background: url(../images/aiwrap.png);
width: 18px;
height: 10px;
margin: 0 0 20px -58px;
position: relative;
}
input[type=text],
input[type=file],
input[type=password],
input[type=email], select {
border: 1px solid #DCDEE0;
vertical-align: middle;
border-radius: 3px;
height: 50px;
padding: 0px 16px;
font-size: 14px;
color: #555555;
outline:none;
width:100%;
}
input[type=text]:focus,
input[type=file]:focus,
input[type=password]:focus,
input[type=email]:focus, select:focus {
border: 1px solid #27A9E3;
}
input[type=submit],
input[type=button]{
display: inline-block;
vertical-align: middle;
padding: 12px 24px;
margin: 0px;
font-size: 18px;
line-height: 24px;
text-align: center;
white-space: nowrap;
vertical-align: middle;
cursor: pointer;
color: #ffffff;
background-color: #27A9E3;
border-radius: 3px;
border: none;
-webkit-appearance: none;
outline:none;
width:100%;
}
hr.hr15 {
height: 15px;
border: none;
margin: 0px;
padding: 0px;
width: 100%;
}
hr.hr20 {
height: 20px;
border: none;
margin: 0px;
padding: 0px;
width: 100%;
}
.copyright{
font-size:14px;
color:rgba(255,255,255,0.85);
display:block;
position:absolute;
bottom:15px;
right:15px;
}
<?php
$server="localhost";//主机
$db_username="root";//你的数据库用户名
$db_password="root";//你的数据库密码 $con = mysql_connect($server,$db_username,$db_password);//链接数据库
if(!$con){
die("can't connect".mysql_error());//如果链接失败输出错误
} mysql_select_db('test',$con);//选择数据库(test是数据库名称)
//字符转换,读库
mysql_query("set character set 'utf-8'");
//写库
mysql_query("set names 'utf-8'");
?>
<?PHP
header("Content-Type: text/html; charset=utf8"); if(!isset($_POST["submit"])){
exit("非法访问!");
}//检测是否有submit操作 include('connect.php');//链接数据库 $name = $_POST['name'];//post获得用户名表单值
$passowrd = MD5($_POST['password']);//post获得用户密码单值,使用MD5加密,不可逆 if ($name && $passowrd){//如果用户名和密码都不为空
$sql = "select * from admin where username = '$name' and password='$passowrd'";//检测数据库是否有对应的username和password的sql
$result = mysql_query($sql);//执行sql
$rows=mysql_num_rows($result);//返回一个数值
if($rows){//0 false 1 true
//登录成功
session_start();//启动Session
$_SESSION['name'] = $_POST['name'];
header("refresh:0;url=sucess.php");//如果成功跳转至sucess.php页面
exit;
}else{
echo "用户名或密码错误,请重新登录!";
echo "
<script>
setTimeout(function(){window.location.href='../login.html';},1000);
</script> ";//如果错误使用js 1秒后跳转到登录页面重试;
} }else{//如果用户名或密码有空
echo "用户名或密码填写不完整,请重新登录!";
echo "
<script>
setTimeout(function(){window.location.href='../login.html';},1000);
</script>";
//如果错误使用js 1秒后跳转到登录页面重试;
} mysql_close();//关闭数据库
?>
<?php
session_start();//初始化session
session_destroy();//注销session
header("location:../login.html");//注销session并跳转
?>
<?php
header("Content-Type: text/html; charset=utf8"); if(!isset($_POST['submit'])){
exit("错误执行");
}//判断是否有submit操作 $name=$_POST['name'];//post获取表单里的name
$password=MD5($_POST['password']);//post获取表单里的password,使用MD5加密,不可逆 include('connect.php');//链接数据库 $sql = "select username from admin where username = '$name'";//SQL语句
$result = mysql_query($sql);//执行SQL语句
$num = mysql_num_rows($result);//统计执行结果影响的行数
if ($num) {//如果已经存在该用户
echo "<script>alert('温馨提示:用户存在!'); history.go(-1);</script>";
} else {
$q="insert into admin(id,username,password) values (null,'$name','$password')";//向数据库插入表单传来的值的sql
$reslut=mysql_query($q,$con);//执行sql
if (!$reslut){
die('Error: ' . mysql_error());//如果sql执行失败输出错误
}else{
echo "注册成功";//成功输出注册成功
echo "
<script>
setTimeout(function(){window.location.href='../login.html';},1000);
</script>";
//如果注册成功使用js 1秒后跳转到登录页面;
}
}
mysql_close($con);//关闭数据库
?>
<?PHP
ini_set("error_reporting","E_ALL & ~E_NOTICE");
session_start();//启动Session
if(!$_SESSION['name']){
echo "<script language='javascript'>alert('对不起,您未登录!');history.back();</script>";
}
?>
<html lang="cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>欢迎成功进入首页!</title>
</head>
<body>
<h1>当前登录用户:</h1>
<h2>
<?PHP
echo $_SESSION['name'];
?>
</h2>
<a href="logout.php">注销用户</a>
</body>
</html>
<?php ?>
纯手写,如果有不足之处请谅解。
PHP+MySQL登录注册,完整版,详细注释的更多相关文章
- CentOS 6.5以上版本安装mysql 5.7 完整版教程(修订版)
转载自:https://codeday.me/collect/20170524/21861.html 1: 检测系统是否自带安装mysql # yum list installed | grep my ...
- MySql数据库导出完整版(导出数据库,导出表,导出数据库结构)
MySql数据库导出完整版(导出数据库,导出表,导出数据库结构) 用MySqlCE导出数据库脚本时,如数据库中包含中文内容,则导出异常. 现在可以通过mysqldump.exe直接导出数据库脚本步骤如 ...
- 使用sysbench测试mysql及postgresql(完整版)
使用sysbench测试mysql及postgresql(完整版) 转载请注明出处https://www.cnblogs.com/funnyzpc/p/14592166.html 前言 使用sysbe ...
- CI框架下 新浪微博登录接口完整版
https://www.cnblogs.com/yznyzcw/p/3756622.html#top 说明:本贴只适合CI框架.功能实现:登录接口跳转链接成功,获取用户信息(包括最重要的u_id)成功 ...
- Struts2+MySQL登录注册
下载地址:http://download.csdn.net/detail/qq_33599520/9777172 项目结构图: 代码: package com.mstf.action; import ...
- centos6 yum安装mysql 5.6 (完整版)
使用源代码编译安装mysql还是比较麻烦,一般来说设备安装时请网络同事临时开通linux上网,通过yum网络实现快速安装,或配置yum仓库进行内网统一安装. 通过网络快速安装过程如下 一.检查系统是否 ...
- MySQL 锁(完整版)
目录 锁总览 锁的作用 加锁流程 锁对数据库的影响 锁等待 死锁 锁类型 锁范围 锁方式 全局锁 全局读锁 全局QC锁 QC锁存在的问题: 备份锁 backup lock MDL锁 MDL锁类型 MD ...
- Nodejs学习总结 -Express 登录注册示例(二)
项目创建后,我们来做个登录注册实例,详细操作步骤如下. 1.新建项目demo ,具体操作步骤参考上一章内容 https://www.cnblogs.com/Anlycp/ 2.添加mysql和sess ...
- Java Spring+Mysql+Mybatis 实现用户登录注册功能
前言: 最近在学习Java的编程,前辈让我写一个包含数据库和前端的用户登录功能,通过看博客等我先是写了一个最基础的servlet+jsp,再到后来开始用maven进行编程,最终的完成版是一个 Spri ...
随机推荐
- Maven传递依赖的时候,同名包不同版本号的包均会下载,可是编译的时候,仅仅会载入一个高版本号的。
描写叙述,在一个Maven项目中.同一时候依赖了spring-tomcat-weaver 和 struts-core 包.可是spring-tomcat-weaver 须要commons-dige ...
- JavaSE入门学习24:Java面向对象补充
一Java中的Object类 Object类是全部Java类的父类.假设一个类没有使用extendskeyword明白标识继承另外一个类,那么这个类默认 继承Object类. public class ...
- dexposed框架Android在线热修复
移动client应用相对于Webapp的最大一个问题每次出现bug,不能像web一样在server就完毕修复,不须要发版本号.紧急或者有安全漏洞的问题, 假设是Webapp你可能最多花个1,2个小时紧 ...
- 【Linux驱动】TQ2440 DM9000E网卡驱动移植(Linux-2.6.30.4)
花了一天的时间研究了一下Linux-2.6.30.4版本号内核下关于TQ2440 DM9000E的网卡驱动移植.总结一下自己的收获. 事实上.在Linux-2.6.30.4版本号内核下有关于网卡驱动, ...
- poj--3984--迷宫问题(bfs+路径记录)
迷宫问题 Time Limit: 1000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Submit Status D ...
- Django(part4)
一个简单的form表单: #polls/templates/polls/detail.html<h1>{{ question.question_text }}</h1> {% ...
- windows py-faster-rcnn配置
[原创帖!转载请注明] windows faster-rcnn安装一直会出现各种错误,本人在实验室电脑成功安装后,在自己电脑上同样的安装步骤也成功.所以做个总结,希望对大家有帮助. 一:安装环境 1. ...
- SQL中一次插入多条数据
SQL中insert一次可以插入一条数据,我们有三种方法可以一次性插入多条数据. 1. 语法:select 字段列表 into 新表 from 源表 注意事项:此种方法新表是系统自动创建,语句执行前不 ...
- 3DS MAX玩家必看!70个提高渲染速度的小技巧
3DS MAX玩家必看!70个提高渲染速度的小技巧 (注:节省RAM不一定会加快渲染速度.请同学们根据实际情况加以利用.) 1. 尽量限制Ploygon数量,越少渲染速度越快 2. 如果使用Vray, ...
- matplotlib bar函数重新封装
参考: https://blog.csdn.net/jenyzhang/article/details/52047557 https://blog.csdn.net/liangzuojiayi/art ...