<?php
session_start();
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Method:POST,GET');
header("Content-type: text/html; charset=UTF-8");
$raw_post_data = file_get_contents('php://input');
$arr = json_decode($raw_post_data,true);
$username = $arr['username'];
$password = $arr['password'];
$data = login($username,$password);
echo $data;
function login($username,$password){
include_once 'dbconnect.php';
$sql="select * from t_user where username='$username' and password='$password'";
$result = mysqli_query($conn,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
if(!$row){
$data["code"]=-1;
$data["msg"]="login failed";
$data = json_encode($data,true);
return $data;
}else{
$data["code"]=200;
$data["msg"]="success";
$data["username"]=$row["username"];
$data["password"]=$row["password"];
$data = json_encode($data,true);
return $data;
}
}
?>
|