时间:2021-07-01 10:21:17 帮助过:2人阅读
$posts=$_POST;
foreach($posts as $key => $value){
if(empty($value))
exit('非法访问!');
}
foreach ($posts as $key => $value) {
$posts[$key] = trim($value);
}
require ('dbconfig.php');
//注册
function register($username,$password,$email){
$query = "insert userdata values('". $username ."','". $password ."','". $email. "')";
$result=mysql_query($query);
if(!$result){
exit('注册失败!papap');
//die('注册失败'. mysql_error());
}
else{
echo "注册成功!";
}
}
//检查用户名,密码,邮箱格式
function verifyFormat($username,$password,$email){
$result1=preg_match("/^[\x{4e00}-\x{9fa5}]+$/u", $username);
if(strlen($username)<1 || strlen($username)>16 || result1==0){
echo "用户名格式错误!";
return false;
//die("用户名格式错误!");
}
$result2=preg_match("/^\w+$/u", $password);
if(strlen($password)<6 || strlen($password)>17 || result2==0){
echo "密码格式错误!";
return false;
//die("密码格式错误!");
}
$result3=preg_match("/^[a-zA-Z\d]+@[a-zA-Z\d]+\.[com|cn|com.cn|net]+$/u", $email);
if(result3==0){
echo "邮箱格式错误!";
return false;
//die("邮箱格式错误!");
}
return true;
}
$flag=verifyFormat($posts['username'],$posts['password'], $posts['email']);
if($flag)
register($posts['username'],$posts['password'], $posts['email']);
else
die("注册失败!!..");
?>