我正在尝试使我的移动应用程序从我的数据库中与用户登录,但是没有任何效果,我不明白为什么,请帮助!
在我的数据库中,我有utlisateur(id,username, username_canonical, 电子邮件 email_canonical 已启用 盐 密码 上次登录 确认令牌 password_requested_at 角色 (DC2Type:数组)) {{ 我正在将同一张表用于另一个symfony项目}}
login.php
<?php
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
}
// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS')
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}")
exit(0);
include ("db.php");
$data = file_get_contents("php://input");
if (isset($data)) {
$request = json_decode($data);
$username = $request->username;
$password = $request->password;
}
$username= mysqli_real_escape_string($con,$username);
$password = mysqli_real_escape_string($con,$password);
$username = stripslashes($username);
$password = stripslashes($password);
$sql = "select id from utilisateur where username = '$username' and password = '$password'";
$result = mysqli_query($con,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$active = $row['active'];
$count = mysqli_num_rows($result);
// If result matched myusername and mypassword, table row must be 1 row
if($count >0) {
$response= "Your Login success";
}else {
$response= "Your Login Email or Password is invalid";
}
echo json_encode( $response);
?>
login.page.ts
@ViewChild("username") username;
@ViewChild("password") password
data:string;
constructor(public navCtrl: NavController, public alertCtrl: AlertController,
private http: Http, public loading: LoadingController,private router:Router ,private proj :ProjService) {
}
ngOnInit() {
}
signIn(){
if(this.username.value=="" ){
this.presentAlert()
} else
if(this.password.value==""){
this.presentAlert1()
} else
{
var headers = new Headers();
headers.append("Accept",'application/json')
headers.append('Content-Type', 'application/json' )
let options = new RequestOptions({ headers: headers });
let data = {
username: this.username.value,
password: this.password.value
};
this.presentLoading().then(() => {
return this.http.post('http://localhost/proj1_server/login.php',data,options)
.map((res : Response) => res.json()
)
.subscribe( res => {
console.log(res)
this.router.navigate(['chantier'])
})
})
} }