首页 > 代码库 > 注册核心代码recevier.php
注册核心代码recevier.php
<?php
//加载配置文件
include ‘../init.php‘;
//连接数据库
include DIR_CORE.‘MYSQLDB.php‘;
//接受表单传送过来的信息
$username = trim($_POST[‘username‘]);
$password1 = trim($_POST[‘password1‘]);
$password2 = trim($_POST[‘password2‘]);
$vcode = trim($_POST[‘vcode‘]);
//判断数据的合法性
if(empty($username) || empty($password1) || empty($password2) ){
header("refresh:2;url=./register.php");
die("用户名或密码不能为空,请重新注册!");
}
if(strlen($username) >20){
header("refresh:2;url=./register.php");
die("用户名的有效长度不能超过20位,请重新注册!");
}
if($password1 !== $password2){
header("refresh:2;url=./register.php");
die("密码前后不一致,请重新注册!");
}
if(strlen($password1) <6 || strlen($password1) >16){
header("refresh:2;url=./register.php");
die("密码有效长度为6-16位,请重新注册!");
}
$sql = "select * from user where user_name = ‘$username‘";
$result = my_query($sql);
if(mysql_affected_rows()>0){
header("refresh:2;url=./register.php");
die("用户名已存在,请重新注册!");
}
//插入数据
$password1=md5($password1);
$sql = "insert into user values(null,‘$username‘,‘$password1‘) ";
$result=my_query($sql);
if($result){
header("refresh:2;url=./login.php");
die("注册成功!2秒后跳转到登录界面");
}else{
header("refresh:2;url=./register.php");
die("发生未知错误,请重新注册!");
}
注册核心代码recevier.php