PHP 简单的注册方法

public function logindb()
 {
  $data = $this->request->post();
  $name = $data['user_name'];
  $pwd = $data['user_password'];
  if (preg_match('/^[A-Za-z0-9_\x{4e00}-\x{9fa5}]{3,5}$/u',$name)) {
   if (preg_match('/^[A-Za-z0-9_\.]{6,8}$/',$pwd)) {
   $pwd = md5($data['user_password']);
   $querypwd = md5($data['Password']);
   $time = date('Y-m-d',time());
   $info = Db::table('user')->where('user_name',$name)->find();
   $Cname = $info['user_name'];
   $Cpwd =  $info['user_password'];
    if ($querypwd != $pwd) {
    echo "<script>alert('您输入的确认密码与密码不一致,请重新输入');location.href=''</script>";
    }else{
     if ($name == $Cname) {
      echo "<script>alert('您输入的用户已存在,请重新输入');location.href=''</script>";
     }
      $list = ['user_name'=>$name,'user_password'=>$pwd,'addtime'=>$time];
      $demo = Db::table('user')->insert($list);
      if ($demo) {
       $this->redirect('index/login/login');
       }else{
      echo "<script>alert('注册失败,请重新注册');location.href=''</script>";
       }
     }
    }else{
      echo "<script>alert('密码是由6到8位字母、数字、点、下划线构成');location.href=''</script>";

     }
   }else{
      echo "<script>alert('用户名必须是由三到五位汉字或者字母开头可以带数字的三到五位构成');location.href=''</script>";
   }
 }
posted @ 2018-08-10 15:09  阿拉神苗  阅读(417)  评论(0编辑  收藏  举报