mvc下实现登录

tpl文件

<script>

var xhr;
function select1(){
 if(window.ActiveXobjec){
xhr = new ActiveXobjec( "Microsoft.XMLHTTP");}
else if(window.XMLHttpRequest){
     xhr = new XMLHttpRequest();
}
var url ="index.php?c=shouye&a=dld";
   xhr.open("POST",url,true);
   xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   xhr.onreadystatechange=callback;
   var user=document.getElementById('username').value;
   var pass=document.getElementById('password').value;
   //alert(username);
   //var data="username="+username+"&password="+password;
   if(user!=''&&pass!='')
   {
   var username=document.getElementById('username').value;
   var password=document.getElementById('password').value;  
   xhr.send("username="+username+"&password="+password);
   }
   else{
   alert('账号或密码不能为空');
   }


function callback(){


if(xhr.readyState==4)
{
   if(xhr.status==200){
  if(xhr.responseText=='you'){
 
  alert('登陆成功');
window.open("index.php?c=shouye&a=show");
  }else{
  alert('登陆失败,请注册');
  window.open("index.php?c=liuyan&a=zhuce");
  }
   
  }
}}

}

<body>

   <input type="button" value="注册" οnclick="select1()"/>

</body>


.controller文件

public function dldAction(){
    $username=$_POST['username'];
$password=$_POST['password'];
$dlModel=new dlModel('localhost','root','123','shouye');//file_put_contents("e://text.txt",$rows,FILE_APPEND);
$rows = $dlModel->dl($username,$password);
session_start();
$_SESSION["username"]=$username;
if($rows)
  {echo 'you';}
else{echo 'kong';}
return $rows;
   }
}


model文件

<?php
class dlModel extends baseModel{


public function insert($username,$password){
  $sql="insert into user(user,password) value('".$username."','".$password."')";
  //file_put_contents("e://text.txt",$sql,FILE_APPEND);
  $result=mysql_query($sql);
 $row=mysql_fetch_assoc($result);
 //file_put_contents("e://text.txt",$result,FILE_APPEND);
return $row;
}
public function dl($username,$password){
$sql = "select * from user where username='".$username."' and password='".$password."'";
$res = mysql_query($sql);


$rows=mysql_fetch_assoc($res);
//file_put_contents("e://text.txt",$rows,FILE_APPEND);


return $rows;
}
}
?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值