主要是登录注册功能,前端后台验证没有什么,这个大家可以自己加上去,比如过滤啊,正则啊等

还是先放图吧

这是登录及注册界面  点击注册切换到注册界面,点击登录切换到登录界面

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="js/jquery.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css">
body,html{
padding: 0px;
margin: 0px;
}
.header {
width: %;
padding: 0px;
margin: 0px;
background-color: #699C03;
} .header-nav {
min-width: 1170px; height: 50px;
line-height: 50px;
} .header-nav-left {
float: left;
padding-left: 150px;
margin-top: 10px;
} .header-nav-left h3 {
font-size: 18px;
line-height: 25px;
margin: 0px;
color: #fff;
} .header-nav-right {
float: right;
width: 59.9999%;
position: relative;
height: 50px;
} .header-nav-right ul {
padding: 0px;
margin: 0px;
list-style: none;
position: absolute;
right: 25px;
} .header-nav-right ul li {
float: left;
margin-left: 5px;
color: #fff;
} .header-nav-right ul li a {
color: #fff;
text-decoration: none; }
.user{
min-width:980px;
text-align: center;
margin: 0px;
padding: 0px;
position: relative;
}
.user-list{
width:470px;
height: 250px;
padding: 15px;
margin: 20px auto;
position: relative;
border: 1px solid #DBDBDB;
}
.user-list ul{
list-style: none;
width: %;
overflow: hidden;
height: 250px;
position: relative;
padding: 10px 0px;
margin: 0px;
}
.user-list ul li{
width: %;
list-style: none;
margin-bottom:15px;
}
.user-list ul li i{
color: red;
}
.user-list ul li label{
display: inline-block;
width:%;
text-align: right;
font-size:16px;
margin-right: 10px;
font-family: "微软雅黑"; }
.user-list ul li input{
display: inline-block;
border: 1px solid #DBDBDB;
border-radius:4px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
-ms-border-radius:4px;
height: 30px;
padding: 2px 5px;
vertical-align:middle;
}
.buttons{
width: %;
height:35px;
padding: 5px 10px;
position: absolute;
bottom: 40px;
left: 0px;
right: 0px;
}
.openbutton,.onbutton{
display: inline-block;
width: %;
}
.buttons button{
width: %;
color: #fff;
padding: 5px 10px;
background-color: #4CB0F9;
border: 1px solid #4CB0F9;
border-radius: 4px;
vertical-align: middle;
height: 35px;
line-height: 25px;
cursor:pointer;
}
#form2{
display: none;
}
</style>
</head>
<body>
<div class="header">
<div class="header-nav">
<div class="header-nav-left">
<h3>网站后台管理</h3>
</div>
<div class="header-nav-right">
<ul>
<li><span>欢迎到来到网站后台</span></li>
<li><a href="" onclick="window.location.reload()">主菜单</a></li>
<li><a href="">网站首页</a></li> <li><a href="Index.html">后台主页</a></li>
<li><a href="">内容管理</a></li>
<li><a href="">退出</a></li>
</ul>
</div>
</div>
</div>
<div class="user">
<div class="user-list">
<form id="form1" action="" method="post">
<ul>
<li><label>用户名</label><input type="text" name="username" id="username" placeholder="手机号码或邮箱"/></li>
<li><label>密码</label><input type="password" name="pass" id="pass" placeholder="6-15位密码" /></li>
<div class="buttons">
<a class="onbutton"><button type="submit" id="onsubmit">登录</button></a>
<a class="openbutton"><button type="submit" id="getform2">注册</button></a>
</div>
</ul>
</form>
<form id="form2" action="" method="post">
<ul>
<li><label>用户名</label><input type="text" name="username" id="getusername" placeholder="手机号码或邮箱"/><i>*</i></li>
<li><label>密码</label><input type="password" name="pass" id="getpass" placeholder="6-15位密码" /><i>*</i></li>
<div class="buttons">
<a class="getbutton"><button type="submit" id="getsubmit">提交注册信息</button></a>
<p>已有账号立即<a href="#" id="getform1">登录</a></p>
</div>
</ul>
</form>
</div>
</div>
<script type="text/javascript">
$(function(){
$(".onbutton #onsubmit").on('click',function(){
var $username = $("#username").val(),
$pass = $("#pass").val();
if($username=='' || $pass==''){
alert("用户名及密码不能为空");
return false;
}else{
var datas={
username:$username,
pass:$pass
};
$.ajax({
url:'user.php',
type:'post',
dataType:'json',
data:datas,
success:function(result){
if(result=='nameerror'){
alert('用户名不存在');
}else if(result=="passerror"){
alert("密码错误");
}else{
window.location.href = 'http://www.sogou.com';//登录成功跳转
}
},
error:function(){
alert('false');
}
})
}return false;
})
$("#getsubmit").click(function(){
var $username = $("#getusername").val(),
$pass = $("#getpass").val();
if($username=='' || $pass==''){
alert("用户名及密码不能为空");
return false;
}else{
var datas={
username:$username,
pass:$pass
}
$.ajax({
url:'adduser.php',
type:'post',
data:datas,
dataType:'json',
success:function(reslut){
if(reslut=="repeat"){
alert("该用户名已存在");
}else if(reslut=='success'){
alert("注册成功");
//注册成功后立即切换至登录表单,并记住用户名及密码;
$("#form2").hide();
$("#form1").show();
$("#username").val($username);
$("#pass").val($pass);
}
else{
alert('false');
}
}
})
}return false;
})
})
</script>
<script type="text/javascript">
document.getElementById('getform2').onclick = function(){
document.getElementById('form1').style.display= 'none';
document.getElementById('form2').style.display= 'block';
return false;
}
document.getElementById('getform1').onclick = function(){
document.getElementById('form2').style.display= 'none';
document.getElementById('form1').style.display= 'block';
return false;
} </script>
</body>
</html>

以上是前端代码

下面贴后台代码  ,登录

<?php
    @header("content-type:text/html;charset=utf8");
    $conne = mysql_connect("localhost","root","root")or die("数据库用户名密码错误".@mysql_error());
    $select =mysql_select_db("test",$conne);
    $utf = mysql_query("set names utf8");
    $username=$_REQUEST['username'];
    $pass = $_REQUEST['pass'];
    $arrays = array(array('one'=>'nameerror','two'=>'passerror'));
    $sqlname = mysql_query("select count(*) from user where username= '$username'");
    $row = mysql_fetch_row($sqlname);
    $num = $row[0];
    //查看用户是否存在
    if(!$num){
        echo json_encode($arrays[0]['one']);//不存在返回nameerror        
    }else{
        $sqlpass = mysql_query("select pass from user where username='$username'");//返回一个句柄;
        $passarray = mysql_fetch_row($sqlpass);//获得一个只有一行数据的数族
        $passval = $passarray[0];//这里才是对应用户的密码
        //判断该用户的密码是否正确
        if($passval!=$pass){
            echo json_encode($arrays[0]['two']);//不正确返回passerror
        }
    }
?>

注册

<?php
@header("content-type:text/html;charset=uft8");
$conne = mysql_connect("localhost","root","root")or die("数据库用户名或密码错误".@mysql_error());
$select = mysql_select_db("test",$conne)or die("数据库用户名或密码错误".@mysql_error());
$utf = mysql_query("set names utf8");
$username= $_REQUEST['username'];
$pass = $_REQUEST['pass'];
$arrays = array(array("one"=>'repeat','two'=>'success'));
$sql = mysql_query("select count(*) from user where username='$username'");
$row = mysql_fetch_row($sql);
$num = $row[];
//判断用户名是否已经被注册了
if($num == ){
echo json_encode($arrays[]['one']);//被注册返回repeat
}else{
mysql_query("insert into user(username,pass) values('$username','$pass')");
echo json_encode($arrays[]['two']);
}
?>

php+ajax 登录注册页面的更多相关文章

  1. 登录注册页面html模版

    登录注册页面html模版 地址:http://download.csdn.net/detail/xiaosongaixiaoqian/5432033

  2. /*用户登录注册页面输入框的设置*/<span>的使用

    <!DOCTYPE html> /*用户登录注册页面输入框的设置*/ <html lang="en"> <head> <meta char ...

  3. node.js实现简单的登录注册页面

    首先需要新建四个文件 一个服务器js 一个保存数据的txt 一个登陆.一个注册页面html 1.注册页面 <!DOCTYPE html> <html lang="en&qu ...

  4. php登录注册页面及加载

                           php注册界面                               <h1>注册页面</h1> <form acti ...

  5. php做登录注册页面及加载

    //SQL注入攻击 //1.过滤用户的输入 //2.使用预处理语句 //3.写代码的时候尽量避免 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1. ...

  6. javaWeb登录注册页面

    简单的登陆注册页面 1.配置JDBC驱动连接数据库 2. 配置struts2框架 3. 利用1 2完成登录页面, 注意做到不耦合,即servlet Api和控制器完全脱离) 4. 利用1 2 制作注册 ...

  7. HTML登录注册页面简单实现

    github:传送门 , 码云: 传送门 效果参考: 登录页面,注册页面 使用了bootstrap,jQuery. 后端使用的CGI处理表单,存入MySQL数据库.(之后更新) 登录页面源码 < ...

  8. SpringBoot 拦截器--只允许进入登录注册页面,没登录不允许查看其它页面

    SpringBoot注册登录(一):User表的设计点击打开链接 SpringBoot注册登录(二):注册---验证码kaptcha的实现点击打开链接 SpringBoot注册登录(三):注册--验证 ...

  9. Django内置form表单和ajax制作注册页面

    settings.py import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_D ...

随机推荐

  1. CSS百分比定义高度的冷知识

    当我们给块级元素设置响应式高度的时候,例如给div设置height=50%,往往没能看到效果. 原因是百分比的大小是相对其父级元素宽高的大小,如最外层元素设置的百分比是对应屏幕而言的. 需要了解的是对 ...

  2. Android开发-取消程序标题栏或自定义标题栏

    注:本文由Colin撰写,版权所有!转载请注明原文地址,谢谢合作! 在Android开发中,跟据需要我们有时候需要自定义应用程序的标题栏或者取消程序的标题栏,下面本菜鸟在此记录与分享一下自己使用的方法 ...

  3. CF memsql Start[c]UP 2.0 B

    CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...

  4. java.lang.NoSuchFieldError 异常原因

    一般都是因为 class 或 jar 包重复 导致的 , 也有可能是编译器的问题. 我碰到的问题是,在项目api 接口jar包里定义了一个Config.java,然后在业务层service 项目 的相 ...

  5. 《UNIX环境高级编程第三版》apue.h等源码文件的编译安装

    操作系统:Ubuntu 12/14 1.下载书中的源代码:点击下载 2.编译 tar -zxvf *.tar.gz cd ./apue.3e make 报错: can,t find -lbsd 解决办 ...

  6. MySQL数据类型 int(M) 表示什么意思?详解mysql int类型的长度值问题

    MySQL 数据类型中的 integer types 有点奇怪.你可能会见到诸如:int(3).int(4).int(8) 之类的 int 数据类型.刚接触 MySQL 的时候,我还以为 int(3) ...

  7. JS 做的鼠标放大镜(初级)

    这今天我们学习鼠标的各种事件,我给大家分享一下鼠标放大镜的效果. 希望有兴趣的朋友可以一块交流. <!DOCTYPE html><html> <head> < ...

  8. C#高级编程笔记 Day 8, 2016年9月 28日 (数组)

    1.数组的初始化 声明了数组后,就必须为数组分配内存,以保存数组的所有元素.数组是引用类型,所以必须给它分配堆上的内存,为此,应使用 new 运算符,指定数组中元素的类型和数量来初始化数组的变量.若使 ...

  9. jstl 小总结 以及 jstl fn

    1.1.1 JSTL的使用 JSTL是JSP标准标签库.结合EL替换传统页面的<%%> * JSTL如果不会用.也是可以使用<%%>.但是一般在大公司使用JSTL.进入小公司. ...

  10. java2

    1:关键字(掌握) (1)被Java语言赋予特定含义的单词 (2)特点: 全部小写. (3)注意事项: A:goto和const作为保留字存在. B:类似于Notepad++这样的高级记事本会对关键字 ...