thinkphp登记

WBOY
WBOYOriginal
2016-06-13 10:36:50707browse

thinkphp注册

1、html代码


                   
                       
                         
                               
                               
                           
                       
                               
                               
                           
                           
                               
                               
                           
                           
                               
                               
                           
                             
                               
                               
                           
                            
                           
                           
                       
                             
                               
                               
                           
                            
                           
                       
                   
如果没有会员请注册会员
用户名: *
密码: *
重复密码: *
邮箱: *
验证码:

                          thinkphp登记

                           

                    




<script><br> function ref(){<br> document.getElementById('reg').src="__URL__/regh/random/"&#43;Math.random();<br> }<br></script>


2、后台代码

//接受提交的内容

 function reglog(){
     //防止页面乱码
 
     header('Content-type:text/html;charset=utf-8');
     //$this->uadd('Users');
 
     //echo $_POST['regx'];
     if (md5($_POST['regx']) != $_SESSION['verify']) {
         echo '<script>alert("验证码错误");window.location.href="'.__URL__.'/userReg"</script>';
     
     }
     else {
         
         $this->uadd('Users');
 
         echo '<script>alert("注册成功");window.location.href="'.__URL__.'/userReg"</script>';
         
 
     }
     
 }


//引入自己封装好的调用内部验证码的方法

 function regh(){
            //自己封装好的调用内部验证码的方法
        $this->proving();
            
            
    }




3、判断提交的表单中的内容是否符合要求

class UsersModel extends Model{
    protected $_validate   =   array(
    
            array('users_name','require','姓名不能为空'), //默认情况下用正则进行验证
            array('users_name','','帐号名称已经存在!',0,'unique',1), // 在新增的时候验证name字段是否唯一
            array('users_name','checklen','用户名长度应该在6-15位',0,'callback'),
            array('users_pass','require','密码不能为空'), //默认情况下用正则进行验证
            array('users_pass','checklen','密码长度应该在6-15位',0,'callback'),
            
            array('users_repass','users_pass','确认密码不正确',0,'confirm'), // 验证确认密码是否和密码一致
            array('users_email','RegMail','邮箱格式不对',0,'callback'),
                
            
            array('regx','require','请输入验证码'), //默认情况下用正则进行验证
                    
                    
            
    );
    
    protected $_auto=array(
                
                    array('users_pass','md5',3,'function'),
                
    
    );

function checklen($data){
  if(strlen($data)>15||strlen($data)   return false;
  }else{
   return true;
  }
 }
 function RegMail($data){
     if($data==""){
             
         return true;
     }
     else{
         if(preg_match("/^[0-9a-zA-Z]+(?:[\_\-][a-z0-9\-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\.[a-zA-Z]+$/i", $data)){
             return true;
         }else{
 
             return false;
         }
     }
 
 }    
    
 
}
?>







Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn