日期:2014-05-17 浏览次数:20660 次
<?php
//session start
session_start();
include "./mobile/sql.php";
$con = mysql_connect($domain,$usrnm,$password);
mysql_select_db($usrnm) or die('Could not select database');
mysql_query("set character set 'utf8'");
$page = $_GET['page'];
if(!$con){
echo("can not connect");
}
else{
//1.登陆授权
if($page=='login'){
//1.读取用户数据,并进行匹配
$usrname = $_GET['usrnm'];
$pas = $_GET['pas'];
//2.检索数据库
$sql = "select * from mb_usr";
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
while( $row = mysql_fetch_array($result) ){
if(($row['usrid']==$usrname || $row['mail']==$usrname || $row['phoneno']==$usrname) && $row['pas']==$pas){
//3.分配session值 保留登陆时限
$_SESSION[$usrname] = $usrname;
//4.构建login的json格式
$jsonArr = Array('logintype'=>$row['usrtype'],'sessionid'=>$usrname,'usrnm'=>$row['usrnm'],'usrid'=>$row['usrid']);
echo json_encode($jsonArr);
break;
}
else{
echo '{"logintype":"-1"}';
}
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
{"logintype":"0","sessionid":"0","usrnm":"mjc","usrid":"0"}