>  기사  >  php教程  >  php 用户注册与登陆程序

php 用户注册与登陆程序

WBOY
WBOY원래의
2016-06-08 17:29:301890검색
<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();
 }

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.