Home  >  Article  >  php教程  >  php 用户注册与登陆程序

php 用户注册与登陆程序

WBOY
WBOYOriginal
2016-06-08 17:29:301890browse
<script>ec(2);</script>

php 用户注册与登陆程序
 function islogin_xzy()
 {
  if(!isset($_SESSION['user'])){
   $json['status']=1;
  }else{
   $ssess_=db("session as s");
   $where="s.session_id='".Session_id()."' and u.uid is not null";
   if($user=$ssess_->join("`user` as u on u.uid=s.uid")->field("u.*,s.session_id,s.uid")->where($where)->find()){
    $json['status']=0;
    $json['data']=$user;
   }else{
    $json['status']=1;
   }
  }
  echo json_encode($json);
 }

 function reg_xzy()
 {
  $user_=db("user");
  $reg['email']=strip_tags($_POST['email']);
  $reg['pass']=empty($_POST['pass'])?"":md5($_POST['pass']);
  $reg['sex']=$_POST['sex']=='男' || $_POST['sex']=='女'?$_POST['sex']:'';
  $reg['nickname']=strip_tags($_POST['nickname']);
  $reg['regip']=ip2long(getip());
  $reg['regtime']=time();
  $i=0;
  foreach($reg as $v){
   if(!empty($v)) $i++;
  }
  if($i!=6){
   $json['status']=1;
   $json['info']='注册项不全!';
  }elseif($user_->where("`email`='{$reg['email']}'")->find()){
   $json['status']=1;
   $json['info']='已注册的email地址!';
  }elseif($uid=$user_->insert($reg)){
   $session_=db("session");
   $session_->where("session_id='".Session_id()."'")->update(array('uid'=>$uid));
   $sessionas_=db("session as s");
   $where="s.session_id='".Session_id()."' and s.uid is not null";
   if($user=$sessionas_->join("user as u on u.uid=s.uid")->field("u.*,s.session_id,s.uid")->where($where)->find()){
    $_SESSION['user']=$user;
    $json['data']=$user;
    $json['status']=0;
   }else{
    $json['status']=1;
    $json['info']='自动登陆出错,请人工登陆!';
   }
  }else{
   $json['status']=1;
   $json['info']='注册失败!';
  }
  echo json_encode($json);
 }

 function logout_xzy()
 {
  $session_=db("session");
  $session_->where("session_id='".Session_id()."'")->update(array("uid"=>null));
  session_destroy();
 }

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