php注册页和登录页教程源码js

2018年10月22日22:12:04 发表评论 1,687
第一步、创建用户数据表
<?php
//新建一个php文件,复制该代码粘贴到php文件中,填写您的数据库信息,保存,然后在浏览器中访问该php文件。

$conn = mysqli_connect('您的数据库地址','您的数据库用户名','您的数据库密码','您的数据库名称') or die("数据库链接错误");
mysqli_query($conn,"set names 'utf8'");//写库编码
echo "<h1 style='text-align:center;color:blue'>深蓝源码安装程序</h1><hr/><div style='text-align:center;'>";
$sql_table = "CREATE TABLE slms_system_users(
       id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY 
KEY,  
       uname varchar(30) NOT NULL COMMENT '用户名', 
       name varchar(60) COMMENT '用户昵称',
	   pass varchar(32) NOT NULL COMMENT '密码',
	   class char(60) NOT NULL COMMENT '任职',
	   regdate int(11) UNSIGNED NOT NULL COMMENT '注册时间',
	   score int(11)  COMMENT '积分',
	   Jurisdiction int(1) NOT NULL COMMENT '用户权限',
	   logindate int(11) UNSIGNED NOT NULL COMMENT '最后登录时间',
	   mobile char(11) NOT NULL COMMENT '手机号码',
	   email varchar(60) NOT NULL COMMENT '电子邮箱',
	   monthly int(11) UNSIGNED COMMENT '包月到期'
	   )";
if ($conn->query($sql_table) === TRUE) {
echo "恭喜您!slms_system_users会员表安装成功<hr/>"; 
} else {
echo "您已安装了slms_system_users会员表,无需再次安装<hr/>";  
}

echo "<a href='/'>回到主页</a><hr/><a href='/admin'>回到后台</a></div><hr/>";

//关闭数据库链接

$conn->close();
?>
第二步、注册页面的php写法
<?php

define('SLMS_URL','http://localhost:86');//当前域名
define('SLMS_SITE_NAME','深蓝学生管理系统');//网站名称
define('SLMS_META_KEYWORDS','深蓝源码,深蓝学生管理系统');//网站关键词
define('SLMS_META_DESCRIPTION','深蓝学生管理系统是一个比较完善和个性化的管理系统,可以查看学生成绩,和学生在校情况等信息。');//网站说明
define('SLMS_BA','黔ICP备1500312号');//备案号
define('SLMS_DB_TYPE','mysql');//数据库类型,此处必须是mysql
define('SLMS_DB_CHARSET','UTF-8');//页面编码,此处必须是UTF-8
define('SLMS_DB_PREFIX','SLMS');
define('SLMS_DB_HOST','localhost');//数据库地址
define('SLMS_DB_USER','root');//数据库用户名
define('SLMS_DB_PASS','root');//数据库密码
define('SLMS_DB_NAME','slms_slxsglxt');//数据库名称
define('SLMS_SJBQZ','slms_');//数据表前缀,安装完成后,请勿修改
define('SLMS_BANBEN','V1.0');//版本号
define('SLMS_URL_LOGIN',SLMS_URL.'/reg/login.php');//登录地址
define('SLMS_URL_REG',SLMS_URL.'/reg/reg.php');//注册地址
define('SLMS_URL_ZHUXIAO',SLMS_URL.'/reg/logout.php');//注册地址
define('SLMS_YZMCW','验证码错误');
define('SLMS_QCXSR','请重新输入!');
define('SLMS_DLCG','登录成功!');
define('SLMS_ZZCG','注册成功!');
define('SLMS_HYHY','欢迎会员');
define('SLMS_YHMWK','用户名不能为空!');
define('SLMS_YHMTS','用户名不能少于6位字符!');
define('SLMS_DQYHYCZ','当前用户名已被占用!');
define('SLMS_SJGSCW','手机号码必须是11位数字!');
define('SLMS_SJBZC','该手机号已被注册!');
define('SLMS_YXCW','该邮箱已被注册!');
define('SLMS_YXGSCW','邮箱格式错误!');
define('SLMS_MMWK','密码不能为空!');
define('SLMS_MMTD','密码不能少于8个字符!');
define('SLMS_MMJYCW','密码不正确!');
define('SLMS_CFMMWK','重复密码不能为空!');
define('SLMS_CFMMBYZ','两次输入密码不一致!');
define('SLMS_ZXCG','注销成功!');
define('SLMS_YHMBCZ','用户名不存在!');
define('SLMS_QXZ','请选择<a href="/">返回首页</a><br/>或<a href="#">关闭当前页</a>');
//以上常量建议新建一个php文件保存,然后其他文件调用就行了
session_start();
if($_SESSION['uid'] != 0){
	header("Location:".SLMS_URL); 
	exit();
}

if (isset($_REQUEST['do'])) { 
$conn = mysqli_connect(SLMS_DB_HOST,SLMS_DB_USER,SLMS_DB_PASS,SLMS_DB_NAME) or die("数据库链接错误");
mysqli_query($conn,"set names 'utf8'");//写库
$slms_qz = SLMS_SJBQZ.'system_users';
$slms_br = '<br/>';
//验证用户名
if (!isset($_POST['u'])) { 
 $slms_yhm = SLMS_YHMWK.$slms_br;//用户名为空
}else{
	 if(strlen($_POST['u']) <= 5){
		 $slms_yhm = SLMS_YHMTS.$slms_br;//用户名太短
	 }else{
		   $slms_u = strtolower($_POST['u']);
		   $result = mysqli_query($conn, "SELECT uname FROM $slms_qz WHERE uname = '$slms_u'");
		   if(mysqli_num_rows($result)){//用户名被占用的情况
			   $slms_yhm = SLMS_DQYHYCZ.$slms_br;
		   }else{
			   $slms_yhm = '';
		   }
	 }
}
//密码部分
if (!isset($_POST['p'])) { 
 $slms_p = SLMS_MMWK.$slms_br;
}else{
	 if(strlen($_POST['p']) <= 7){
		 $slms_p = SLMS_MMTD.$slms_br;
	 }else{
		 $slms_p = '';
	 }
}

//重复密码
if (!isset($_POST['rp'])) { 
 $slms_rp = SLMS_CFMMWK.$slms_br;
}else{
		 if($_POST['rp'] != $_POST['p']){ 
		    $slms_rp = SLMS_CFMMBYZ.$slms_br;
		 }else{ 
			$slms_rp = '';
		 }
}

//手机号部分;
if (isset($_REQUEST['mo'])) {
	$slms_mo = strtolower($_REQUEST['mo']);
	if(strlen($slms_mo) != 11){
		$slms_mots = SLMS_SJGSCW.$slms_br;
	}
	$phonenumber = $slms_mo;
	if(!preg_match("/^1[34578]{1}\d{9}$/",$phonenumber)){
		$slms_mots = SLMS_SJGSCW.$slms_br;
	}else{//验证手机号是否被注册
	   $result = mysqli_query($conn, "SELECT mobile FROM $slms_qz WHERE mobile = '$slms_mo'");
	   if(mysqli_num_rows($result)){
		   $slms_mots = SLMS_SJBZC.$slms_br;
	   }else{
		   $slms_mots = '';
	   }
	}
}

//电子邮件部分
if (isset($_REQUEST['m'])) {
	$email= strtolower($_REQUEST['m']);
	$pattern="/([a-z0-9]*[-_.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[.][a-z]{2,3}([.][a-z]{2})?/i";
	if(!preg_match($pattern,$email)){
		$slms_m = SLMS_YXGSCW.$slms_br;
	} else{
		   $result = mysqli_query($conn, "SELECT email FROM $slms_qz WHERE email = '$email'");
		   if(mysqli_num_rows($result)){//用户名被占用的情况
			   $slms_m = SLMS_YXCW.$slms_br;
		   }else{
			   $slms_m = '';
		   }
		     
	}
}

//验证码部分
if (isset($_REQUEST['c'])) {
	if(strtolower($_REQUEST['c']) != $_SESSION['authnum_session']){
		$slms_c = SLMS_YZMCW.$slms_br;
	}else{
		$_SESSION['c'] = 1; 
		$slms_c = '';
	}

}

	if($slms_yhm =='' && $slms_p =='' && $slms_rp=='' && $slms_mots =='' && $slms_m =='' && $slms_c == ''){
		$slms_zcmm = md5($_REQUEST['p']);
		$date = time();
		
		$sql = "INSERT INTO $slms_qz (uname,name, pass,class,regdate,score,Jurisdiction,logindate,mobile,email)
                              VALUES ('$slms_u', '', '$slms_zcmm','普通会员','$date',0,5,'$date','$slms_mo','$email')";
			if (!mysqli_query($conn, $sql)) {
				echo "Error: " . $sql . "<br>" . mysqli_error($conn);
			} else {
				$retval = mysqli_query( $conn, "SELECT uname, id FROM $slms_qz WHERE uname = '$slms_u'" );
				$row = mysqli_fetch_array($retval);
				$slms_uid = $row['id'];
				$_SESSION['uid'] = $slms_uid;
				$_SESSION['uname'] = $slms_u;
				$_SESSION['name'] = $slms_u;
				$_SESSION['class'] = '普通会员';
				$_SESSION['Jurisdiction'] = '5';
				$_SESSION['score'] = 0;
				$_SESSION['regdate'] = $date;
				$_SESSION['mobile'] = $slms_mo;
				$_SESSION['email'] = $email;
				 mysqli_free_result($retval);// 释放内存
				echo SLMS_ZZCG;//注册成功!
			}

	}else{
		define('SLMS_TS',SLMS_YZMCW);
		define('SLMS_TSNR',$slms_yhm.$slms_p.$slms_rp.$slms_mots.$slms_m.$slms_c);
		echo $slms_yhm.$slms_p.$slms_rp.$slms_mots.$slms_m.$slms_c;
	}



$conn->close();
exit();
}



?>

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>注册-<?php echo SLMS_SITE_NAME ?></title>
		<link rel="stylesheet" href="/css/reset.css" />
		<link rel="stylesheet" href="/css/common.css" />
		<style type="text/css">
			#yzm{position:relative;}
			#slms_img{width:130px;height:40px;position:absolute;right:0px;top:0px;}
		</style>
	</head>
	<body>
		<div class="wrap login_wrap">
			<div class="content">
				
				<div class="logo"></div>
				
				<div class="login_box">	
					
					<div class="login_form">
						<div class="login_title">
							注册
						</div>
						  <form method="post" id='frmregister' action="">
							<div class="form_text_ipt">
								<input name="u" type="text" placeholder="账号">
							</div>
							<div class="ececk_warning"><span>账号不能为空</span></div>
							<div class="form_text_ipt">
								<input name="p" type="password" placeholder="密码">
							</div>
							<div class="ececk_warning"><span>密码不能为空</span></div>
							<div class="form_text_ipt">
								<input name="rp" type="password" placeholder="重复密码">
							</div>
							<div class="ececk_warning"><span>两次密码不一致</span></div>
							<div class="form_text_ipt">
								<input name="mo" type="text" placeholder="手机号">
							</div>
							<div class="ececk_warning"><span>手机号不能为空</span></div>
							<div class="form_text_ipt">
								<input name="m" type="text" placeholder="电子邮箱">
							</div>
							<div class="ececk_warning"><span>电子邮箱不能为空或格式错误</span></div>
							<div id="yzm" class="form_text_ipt">
								<input name="c" type="text" placeholder="验证码">
								<img id="slms_img" src="" alt="验证码" title="点击刷新"/>
							</div>
							<div class="ececk_warning"><span>验证码不能为空</span></div>
							
							<div class="form_btn">
								<button type="button" onClick="slms_tj()">注册</button>
							</div>
							<div class="form_reg_btn">
								<span>已有帐号?</span><a href="<?php echo SLMS_URL_LOGIN ?>">马上登录</a>
							</div>
						
					<!--	<div class="other_login">
							<div class="left other_left">
								<span>其它登录方式</span>
							</div>
							<div class="right other_right">
								<a href="#">QQ登录</a>
								<a href="#">微信登录</a>
								<a href="#">微博登录</a>
							</div>
						</div>-->
						</form>
					</div>
				</div>
			</div>
		</div>
		<script src="/js/jquery.js"></script>
		<script type="text/javascript">
		 //账号部分
			su = 0;
			smm = 0;
			sqm = 0;
			smo = 0;
			sm = 0;
			sc = 0;
		 $("input").eq(0).blur(function(e){
		  var u = $("input").eq(0).val();
				$.ajax({ 
				type:'post',//提交方式
				url:"/data/reg.Class.php",//提交地址
				data:{u:u},
				success:function(msg,data,success){
				if(msg == ""){
				    $(".ececk_warning").eq(0).hide();
					su = 1;
				}else{
					$(".ececk_warning").eq(0).show().text(msg);
					su = 0;
				}
				
				}})
		
	    });
		$("input").eq(1).blur(function(e){
			var mm = $("input").eq(1).val().length;
			if(mm == 0){
				$(".ececk_warning").eq(1).show().text('密码不能为空!');
				smm = 0;
			}else if(mm <= 6){
				$(".ececk_warning").eq(1).show().text('密码长度不能少于8个字符!');
				smm = 0;
			}else{
				$(".ececk_warning").eq(1).hide();
				smm = 1;
			}
		});
			
		$("input").eq(2).blur(function(e){
			var mm = $("input").eq(1).val();
			var qm = $("input").eq(2).val();
			if(mm != qm){
				$(".ececk_warning").eq(2).show().text('两次输入密码不一致!');
				sqm = 0;
			}else{
				$(".ececk_warning").eq(2).hide();
				sqm = 1;
			}
		});
			
		$("input").eq(3).blur(function(e){
			var mo = $("input").eq(3).val();
			$.ajax({ 
				type:'post',//提交方式
				url:"/data/reg.Class.php",//提交地址
				data:{mo:mo},
				success:function(msg,data,success){
				if(msg == ""){
				    $(".ececk_warning").eq(3).hide();
					smo = 1;
				}else{
					$(".ececk_warning").eq(3).show().text(msg);
					smo = 0;
				}
				}})
		});
		
		$("input").eq(4).blur(function(e){
			var m = $("input").eq(4).val();
			$.ajax({ 
				type:'post',//提交方式
				url:"/data/reg.Class.php",//提交地址

				data:{m:m},
				success:function(msg,data,success){
				if(msg == ""){
				    $(".ececk_warning").eq(4).hide();
					sm = 1;
				}else{
					$(".ececk_warning").eq(4).show().text(msg);
					sm = 0;
				}
				}})
		});
			
		$("#slms_img").attr('src','/captcha.php?'+new Date().getTime());	
		$("#slms_img").click(function(){
			$("#slms_img").attr('src','/captcha.php?'+new Date().getTime());	
		});
		$("input").eq(5).keyup(function(e){
			if($("input").eq(5).val().length !=4){
				$(".ececk_warning").eq(5).show().text('验证码格式不正确!');
				sc = 0;
			}else{
				var c = $("input").eq(5).val();
				$.ajax({ 
				type:'post',//提交方式
				url:"/data/reg.Class.php",//提交地址
				data:{c:c},
				success:function(msg,data,success){
				if(msg == ""){
				    $(".ececk_warning").eq(5).hide();
					sc = 1;
				}else{
					$(".ececk_warning").eq(5).show().text(msg);
					sc = 0;
				}
				}})
			}
		});
		
		function slms_tj(){
			if(su == 0){$(".ececk_warning").eq(0).show();return false;}
			if(smm == 0){$(".ececk_warning").eq(1).show();return false;}
			if(sqm == 0){$(".ececk_warning").eq(2).show();return false;}
			if(smo == 0){$(".ececk_warning").eq(3).show();return false;}
            if(sm == 0){$(".ececk_warning").eq(4).show();return false;}
			if(sc == 0){$(".ececk_warning").eq(5).show();return false;}
			var u = $("input").eq(0).val();
			var mm = $("input").eq(1).val();
			var qm = $("input").eq(2).val();
			var mo = $("input").eq(3).val();
			var m = $("input").eq(4).val();
			var c = $("input").eq(5).val();
			 var dataa = $('#frmregister').serialize();
			$.ajax({ 
				type:'post',//提交方式
				url:"/reg/reg.php?do=slms",//提交地址
				data:dataa,
				success:function(msg,data,success){
				 if(msg = '注册成功!'){
					 alert('恭喜您,注册成功!');
					 window.location.href="/";
				 }else{
					 alert(msg);
				 }
				}
			})	
		}
		
		</script>
	</body>
</html>
第三步,注册时,提交验证的php文件reg.Class.php
<?php

//注意,此部分需要调用注册页面上使用的常量部分,否则会报错!
session_start();
$slms_qz = SLMS_SJBQZ.'system_users';
if (isset($_REQUEST['u'])) { 
   $slms_u = strtolower($_REQUEST['u']);
   if($slms_u == ""){echo SLMS_YHMWK; exit();}
   if(strlen($slms_u) <= 5){echo SLMS_YHMTS; exit();}
   $conn = mysqli_connect(SLMS_DB_HOST,SLMS_DB_USER,SLMS_DB_PASS,SLMS_DB_NAME) or die("数据库链接错误");
   mysqli_query($conn,"set names 'utf8'");//写库
   $result = mysqli_query($conn, "SELECT uname FROM $slms_qz WHERE uname = '$slms_u'");
   if(mysqli_num_rows($result)){//用户名被占用的情况
	   echo SLMS_DQYHYCZ;
	   $conn->close();
	   exit();
   }
	
   $conn->close();
}


//手机号部分;
if (isset($_REQUEST['mo'])) {
	$slms_mo = strtolower($_REQUEST['mo']);
	if(strlen($slms_mo) != 11){
		echo SLMS_SJGSCW;exit();
	}
	$phonenumber = $slms_mo;
	if(!preg_match("/^1[34578]{1}\d{9}$/",$phonenumber)){
		echo SLMS_SJGSCW;exit();
	}else{//验证手机号是否被注册
	   $conn = mysqli_connect(SLMS_DB_HOST,SLMS_DB_USER,SLMS_DB_PASS,SLMS_DB_NAME) or die("数据库链接错误");
	   mysqli_query($conn,"set names 'utf8'");//写库
	   $result = mysqli_query($conn, "SELECT mobile FROM $slms_qz WHERE mobile = '$slms_mo'");
	   if(mysqli_num_rows($result)){//用户名被占用的情况
		   echo SLMS_SJBZC;
		   $conn->close();
		   exit();
	   }

	   $conn->close();
	}
}


//电子邮件部分
if (isset($_REQUEST['m'])) {
	$email= strtolower($_REQUEST['m']);
	$pattern="/([a-z0-9]*[-_.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[.][a-z]{2,3}([.][a-z]{2})?/i";
	if(!preg_match($pattern,$email)){
		echo '邮箱格式错误!';
	} else{
		   $conn = mysqli_connect(SLMS_DB_HOST,SLMS_DB_USER,SLMS_DB_PASS,SLMS_DB_NAME) or die("数据库链接错误");
		   mysqli_query($conn,"set names 'utf8'");//写库
		   $result = mysqli_query($conn, "SELECT email FROM $slms_qz WHERE email = '$email'");
		   if(mysqli_num_rows($result)){//用户名被占用的情况
			   echo SLMS_YXCW;
			   $conn->close();
			   exit();
		   }

		   $conn->close();
	}
	
}

//验证码部分
if (isset($_REQUEST['c'])) {
	if(strtolower($_REQUEST['c']) != $_SESSION['authnum_session']){
		echo SLMS_YZMCW;
	}

}

?>
第四步、php验证码文件的写法
<?php 
//验证码类

session_start();
$_vc = new ValidateCode();  //实例化一个对象
$_vc->doimg();  
$_SESSION['authnum_session'] = $_vc->getCode();//验证码保存到SESSION中


class ValidateCode {
 private $charset = 'abcdefghkmnprstuvwxyzABCDEFGHKMNPRSTUVWXYZ23456789';//随机因子
 private $code;//验证码
 private $codelen = 4;//验证码长度
 private $width = 130;//宽度
 private $height = 50;//高度
 private $img;//图形资源句柄
 private $font;//指定的字体
 private $fontsize = 20;//指定字体大小
 private $fontcolor;//指定字体颜色
 //构造方法初始化
 public function __construct() {
  $this->font = dirname(__FILE__).'/font/elephant.ttf';//注意字体路径要写对,否则显示不了图片
 }
 //生成随机码
 private function createCode() {
  $_len = strlen($this->charset)-1;
  for ($i=0;$i<$this->codelen;$i++) {
   $this->code .= $this->charset[mt_rand(0,$_len)];
  }
 }
 //生成背景
 private function createBg() {
  $this->img = imagecreatetruecolor($this->width, $this->height);
  $color = imagecolorallocate($this->img, mt_rand(157,255), mt_rand(157,255), mt_rand(157,255));
  imagefilledrectangle($this->img,0,$this->height,$this->width,0,$color);
 }
 //生成文字
 private function createFont() {
  $_x = $this->width / $this->codelen;
  for ($i=0;$i<$this->codelen;$i++) {
   $this->fontcolor = imagecolorallocate($this->img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));
   imagettftext($this->img,$this->fontsize,mt_rand(-30,30),$_x*$i+mt_rand(1,5),$this->height / 1.4,$this->fontcolor,$this->font,$this->code[$i]);
  }
 }
 //生成线条、雪花
 private function createLine() {
  //线条
  for ($i=0;$i<6;$i++) {
   $color = imagecolorallocate($this->img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));
   imageline($this->img,mt_rand(0,$this->width),mt_rand(0,$this->height),mt_rand(0,$this->width),mt_rand(0,$this->height),$color);
  }
  //雪花
  for ($i=0;$i<100;$i++) {
   $color = imagecolorallocate($this->img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255));
   imagestring($this->img,mt_rand(1,5),mt_rand(0,$this->width),mt_rand(0,$this->height),'*',$color);
  }
 }
 //输出
 private function outPut() {
  header('Content-type:image/png');
  imagepng($this->img);
  imagedestroy($this->img);
 }
 //对外生成
 public function doimg() {
  $this->createBg();
  $this->createCode();
  $this->createLine();
  $this->createFont();
  $this->outPut();
 }
 //获取验证码
 public function getCode() {
  return strtolower($this->code);
 }
}



?>

 

第五步、登录页代码
<?php



//记住,之前需要调用注册页中用到的常量,不然会报错!
session_start();
if($_SESSION['uid'] != 0){
	header("Location:".SLMS_URL); 
	exit();
};
$slms_qz = SLMS_SJBQZ.'system_users';
$conn = mysqli_connect(SLMS_DB_HOST,SLMS_DB_USER,SLMS_DB_PASS,SLMS_DB_NAME) or die("数据库链接错误");
mysqli_query($conn,"set names 'utf8'");//写库
if (isset($_REQUEST['do'])) { 
	//账号校验
   if (isset($_REQUEST['u'])) { 
   $slms_u = strtolower($_REQUEST['u']);
   if($slms_u == ""){
	   $slms_su = SLMS_YHMBCZ;
	}else if(strlen($slms_u) <= 5){
	   $slms_su = SLMS_YHMBCZ;
   }else{
	  
	   $result = mysqli_query($conn, "SELECT uname FROM $slms_qz WHERE uname = '$slms_u'");
       if(mysqli_num_rows($result)){//用户名被占用的情况
	    $slms_su = '';
       }else{
		$slms_su = SLMS_YHMBCZ;
	   }
   }
  
}
	
//密码校验
   if (isset($_REQUEST['p'])) { 
   $slms_p = $_REQUEST['p'];
   if($slms_p == ""){
	   $slms_sp = SLMS_MMTD;
	}else if(strlen($slms_u) <= 5){
	   $slms_sp = SLMS_MMTD;
   }else{
	   $slms_zcmm = md5($_REQUEST['p']);
	   $retval = mysqli_query( $conn, "SELECT pass, id FROM $slms_qz WHERE pass = '$slms_zcmm'" );
	   $row = mysqli_fetch_array($retval);
	   if($row['pass']==$slms_zcmm){
		  $slms_sp = ''; 
	   }else{
		  $slms_sp = SLMS_MMJYCW; 
	   }
   }
  
}	
	
	
	if (isset($_REQUEST['c'])) { 
		if(strtolower($_REQUEST['c']) == $_SESSION['authnum_session']){
			$slms_sc = '';
		}else{//验证码错误输出提示!
			$slms_sc = SLMS_YZMCW;
		}
	}
	
           if($slms_su == '' && $slms_sp == '' && $slms_sc == ''){
			$retval = mysqli_query( $conn, "SELECT * FROM $slms_qz WHERE uname = '$slms_u'" );
	        $row = mysqli_fetch_array($retval);
				$_SESSION['uid'] = $row['id'];
				$_SESSION['uname'] = $row['uname'];
			   if($row['name'] == ''){
				 $_SESSION['name'] = $row['uname'];  
			   }else{
				 $_SESSION['name'] = $row['name'];
			   }
				$_SESSION['class'] = $row['class'];
				$_SESSION['Jurisdiction'] = $row['Jurisdiction'];
				$_SESSION['score'] = $row['score'];
				$_SESSION['regdate'] = $row['regdate'];
				$_SESSION['mobile'] = $row['mobile'];
				$_SESSION['email'] = $row['email'];
			   $login_date = time();
			     mysqli_query( $conn, "UPDATE $slms_qz SET logindate='$login_date' WHERE uname = '$slms_u'" );
				 mysqli_free_result($retval);// 释放内存
			   define('SLMS_TS',SLMS_DLCG);
			   define('SLMS_TSNR',SLMS_DLCG);
			   include_once(SLMS_DOCUMENT_ROOT."/html/ts.php");
		}else{
		       define('SLMS_TS',$slms_su.$slms_sp.$slms_sc);
		       define('SLMS_TSNR',$slms_su.$slms_sp.$slms_sc);
			   include_once(SLMS_DOCUMENT_ROOT."/html/ts.php");
		}

$conn->close();
exit();
} 


?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title><?php echo SLMS_SITE_NAME ?>后台登录</title>
<meta name="author" content="DeathGhost" />
<link rel="stylesheet" type="text/css" href="<?php echo SLMS_URL ?>/css/style.css" tppabs="css/style.css" />
<style>
	*{margin:0px;padding:0px;}
body{height:100%;background:#16a085;overflow:hidden;}
canvas{z-index:-1;position:absolute;}
	.val_icon{position:relative;}
	.val_icon img{position:absolute;top:0px;left:125px;height:42px;width:90px;}
	.myzh{color:#C7BBCC!important;}
	.myzh a{color:#F1921A;font-size:15px;font-weight:bold;
		border:1px solid #F1921A;border-radius:5px;padding:0px 10px 0px 10px;}
	.dianjitijiao{width:300px;height:150px;position:fixed;top:50%;left:50%;
		margin-left:-150px;margin-top:-80px;border:2px solid #13AB07;
		background:white;z-index:9999;display:none;}
	.title{width:100%;height:36px;margin-top:-6px;z-index:9999;
    background-color: whitesmoke;
    border-bottom: 1px solid rgb(233, 233, 233);
	position:relative;
	}
	.dianjitijiao h5{text-align:center;font-size: 16px;line-height:36px;}
	.dianjitijiao .title a{display:block;width:36px;height:36px;background:#DBDBDB;
		text-align:center;line-height:36px;font-size:20px;position:absolute;top:0px;right:0px;}
	.dianjitijiao .title a:hover{background:#bbb;}
	.ts_text{width:100%;height:110px;position:relative;z-index:9999;}
	.ts_text a{display:block;width:80px;height:30px;background:#DA3E00;color:#fff;font-size:15px;
		line-height:30px;text-align:center;border:1px solid;border-radius:5px;position:absolute;
		left:50%;bottom:20px;margin-left:-40px;z-index:9999;}
	.ts_text a:hover{background:#DE5923;}
	.ts_text p{text-align:center;font-size:16px;margin-top:10px;}
	#slms_bjkz{position:fixed;top:0px;left:0px;background:rgba(0,0,0,0.59);
		display:block;width:100%;height:100%;z-index:888;display:none;}
	</style>
<script src="<?php echo SLMS_URL ?>/js/jquery.js"></script>
<script src="<?php echo SLMS_URL ?>/js/verificationNumbers.js"></script>
<script src="<?php echo SLMS_URL ?>/js/Particleground.js"></script>
</head>
<body>
<dl class="admin_login">
	<form method="post" id='frmregister' action="">
 <dt>
  <strong><?php echo SLMS_SITE_NAME ?></strong>
  <em>教师登录页面</em>
 </dt>
 <dd class="user_icon">
  <input name="u" type="text" placeholder="账号" class="login_txtbx"/>
 </dd>
 <dd class="pwd_icon">
  <input name="p" type="password" placeholder="密码" class="login_txtbx"/>
 </dd>
 <dd class="val_icon">
  <div class="checkcode">
    <input name="c" type="text" id="J_codetext" placeholder="验证码" maxlength="4" class="login_txtbx">
	<img class="J_codeimg" id="myCanvas"  src="" alt="验证码" title="点击刷新" />
  </div>
  <input type="button" value="重新获取" class="ver_btn" onClick="slms_yzm();">
 </dd>
 <dd>
  <input type="button" value="立即登陆" class="submit_btn"/>
 </dd>
 <dd style="height:66px;">
  <p class="myzh">没有账号?立即 <a href="<?php echo SLMS_URL_REG; ?>"> 注册 </a></p> 
  <p>© 2015-2018 <?php echo SLMS_SITE_NAME ?> 版权所有</p>
  <p><?php echo SLMS_BA ?></p>
 </dd>
	</form>
</dl>
<i id="slms_bjkz"></i>
<div class="dianjitijiao">
	<div class="title"><h5>登陆提示</h5><a href="javascript:;"> X </a></div>
	<div class="ts_text">
		<p id="fanhui">登陆成功!</p>
	    <a href="javascript:;">确定</a>
	</div>
	
</div>
<script type="text/javascript">
var cs = 0;
$(document).ready(function() {
  //粒子背景特效
  $('body').particleground({
    dotColor: '#5cbdaa',
    lineColor: '#5cbdaa'
  });
  //验证码
 
  //测试提交,对接程序删除即可

  $(".submit_btn").click(function(){
	  var zh = $(".login_txtbx").eq(0).val();
	  var mm = $(".login_txtbx").eq(1).val();
	  var yzm = $(".login_txtbx").eq(2).val();
	  var yzmgs = $(".login_txtbx").eq(2).val().length;
	  if(zh == ""){$("#slms_bjkz,.dianjitijiao").show();
				   $("#fanhui").text("账号不能为空!");return false;}
	  if(mm == ""){$("#slms_bjkz,.dianjitijiao").show();
				   $("#fanhui").text("密码不能为空!");return false;}
	  if(yzm == ""){$("#slms_bjkz,.dianjitijiao").show();
					$("#fanhui").text("验证码不能为空!");return false;}
	  if(yzmgs != 4){$("#slms_bjkz,.dianjitijiao").show();
					 $("#fanhui").text("验证码格式不正确!");return false;}
	  
			   var dataa = $('#frmregister').serialize();
				$.ajax({ 
					type:'post',//提交方式
					url:"/reg/login.php?do=slms",//提交地址
					data:dataa,
					success:function(msg){
					 var nr = $(msg).find("#tsm").text();
						 $("#slms_bjkz,.dianjitijiao").show();
						 $("#fanhui").text(nr);
					  if(nr == '登录成功!'){
						//  window.location.href="/";
						  cs = 1;
					  } 
					  
					}
				})	
	  
	  });
});
	
	$(".title a").click(function(){
		if(cs != '1'){
			$("#slms_bjkz,.dianjitijiao").hide();
		}else{
			window.location.href="/";
		}
	});
	
	$(".ts_text a").click(function(){
		if(cs != '1'){
			$("#slms_bjkz,.dianjitijiao").hide();
		}else{
			window.location.href="/";
		}
	});
	
	
function slms_yzm(){
	$("#myCanvas").attr('src','/captcha.php?'+new Date().getTime());
}
$("#myCanvas").attr('src','/captcha.php?'+new Date().getTime());	

</script>
</body>
</html>
注意:以上html部分需要引入jquery.js文件,不然js代码不会生效哦!

效果如图所示:

php注册页和登录页教程源码js

php注册页和登录页教程源码js

完整代码下载:

百度云地址链接:https://pan.baidu.com/s/1E10ozNtcVRrCo7CQe2HHLA
提取码:2cwc

使用方法:

1、放在网站根目录,用编辑工具修改 /configs/define.php文件,将数据库信息和域名信息改成您自己的。

2、然后访问    您的域名/install/install.php  进行数据表的安装。

3、注册页面访问:您的域名/reg/reg.php

4、登录页面访问:您的域名/reg/login.php

5、该源码在php7.2版本上运行正常,其他php版本暂未进行测试。

php截取函数:$response = substr($slms, $lpos + 1, $rpos - $lpos -1);

文件下载 深蓝注册登录页面完整源码 软件类型:php,mysql 软件版本:v1.0 资源大小:28M
下载地址
  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: