安卓PHPapi接口实现用户登陆功能,注册同理


/**  * Created by PhpStorm.  * User: Adaministrator  * Date: 2018/3/29  * Time: 15:01  */// 定义接口返回值

$servername = "182.254.147.87";
$username = "数据库账号";
$password = "数据库密码";
$dbname = "数据库名称";
$success = '';
$output = array();
$name = @$_GET['username'];//根据需要自行设置
$psw=@$_GET['password'];
$con = mysqli_connect($servername,$username,$password,$dbname);
if (!$con)
{
    die('Could not connect: ' .mysqli_error($con));
}
mysqli_select_db( $con,$dbname);
$username_table = lib_replace_end_tag($_GET['username']);
$sql="SELECT firstname , lastname FROM myguests where firstname='$username_table' AND lastname='$psw'";

$result =mysqli_query($con,$sql);

if(!$result)
{
    die("Valid result!");
}
$row = mysqli_fetch_array($result,MYSQLI_BOTH);
if ($row>0) {
    $jarr = array();
    while ($rows=mysqli_fetch_array($result,MYSQLI_BOTH)){
        $count=count($rows);
        for($i=0;$i<$count;$i++){
            unset($rows[$i]);
        }
        array_push($jarr,$rows);
    }
    $jobj=new stdclass();
    foreach($jarr as $key=>$value){
        $jobj->$key=$value;
    }
    $jobj = (array)$jobj;
    $arr = array();
    foreach($jobj as $key =>$val)
    {
        $arr[] = $val;
    }
    $newof=array('status'=>'200',
        'success'=>'true',
        'data'=>$arr);
    echo json_encode($newof);

} else {
    echo "0 结果";
}

mysqli_close($con);

function lib_replace_end_tag($str)
{
    if (empty($str)) return false;
    $str = htmlspecialchars($str);
    $str = str_replace( '/', "", $str);
    $str = str_replace("\\", "", $str);
    $str = str_replace(">", "", $str);
    $str = str_replace("<", "", $str);
    $str = str_replace("", "", $str);
    $str = str_replace("", "", $str);
    $str=str_replace("select","select",$str);
    $str=str_replace("join","join",$str);
    $str=str_replace("union","union",$str);
    $str=str_replace("where","where",$str);
    $str=str_replace("insert","insert",$str);
    $str=str_replace("delete","delete",$str);
    $str=str_replace("update","update",$str);
    $str=str_replace("like","like",$str);
    $str=str_replace("drop","drop",$str);
    $str=str_replace("create","create",$str);
    $str=str_replace("modify","modify",$str);
    $str=str_replace("rename","rename",$str);
    $str=str_replace("alter","alter",$str);
    $str=str_replace("cas","cast",$str);
    $str=str_replace("&","&",$str);
    $str=str_replace(">",">",$str);
    $str=str_replace("<","<",$str);
    $str=str_replace(" ",chr(32),$str);
    $str=str_replace(" ",chr(9),$str);
    $str=str_replace("    ",chr(9),$str);
    $str=str_replace("&",chr(34),$str);
    $str=str_replace("'",chr(39),$str);
    $str=str_replace("
"
,chr(13),$str); $str=str_replace("''","'",$str); $str=str_replace("css","'",$str); $str=str_replace("CSS","'",$str); return $str; }