php形成json语句,多出前面一句,怎么去掉!
php源码
<?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"}
[解决办法]
你肯定有include的页面里加这句了