我想做什么 我正在使用angularJS和php在后端的应用程序,我想在我的应用程序中实现身份验证,我尝试下面粘贴的代码,但它不会生成任何错误,任何消息,当我尝试输入用户名和密码我转到view'admin“无论我输入的是什么用户,都意味着它不会检查用户和密码。在表'client'的数据库中,我有:NomClient和mdp(密码)。
我尝试了什么
AngularJs + php authentication
http://www.freewebmentor.com/2017/01/create-simple-login-page-using-angularjs-php-mysql.html
https://gist.github.com/itswadesh/fe290ef2302bdb1c167fd347a8cadb78
.....和许多考试但是徒劳无法
码
的login.html
<ion-content class="padding" ng-controller="loginCtrl">
<div class="list list-inset" >
<label class="item item-input">
<input type="text" placeholder="nom" required="" ng-model="NomClient">
</label>
<label class="item item-input">
<input type="password" placeholder="Password" ng-model="mdp">
</label>
<button class="button button-block button-positive" ng-click="submit()">Login</button>
</ion-content>
app.js
app.controller('loginCtrl', function($scope,$state,$http){
$scope.submit= function(){
const url = 'http://localhost/deb/login.php';
const postBody = {
NomClient: $scope.NomClient,
mdp: $scope.mdp
};
$http.post(url, postBody).then(data => {
$location.path('/admin');
});
};
的login.php
<?php
$data = json_decode(file_get_contents("php://input"));
$connect = mysqli_connect("localhost", "root", "", "tem");
$response['status'] = 0;
$response['message'] = '';
$NomClient=mysqli_real_escape_string($connect, $data->NomClient);
$mdp=mysqli_real_escape_string($connect, $data->mdp);
$query = 'SELECT * FROM `client` WHERE NomClient = "'.$NomClient.'" AND mdp= "'.$mdp.'"';
if(mysqli_connect_errno()){
$response['status'] = 0;
$response['message'] = "Failed to connect to MySQL: ".mysqli_connect_error();
echo jsone_encode($response);exit;
}
$result = mysqli_query($connect, $query);
$rowcount=mysqli_num_rows($result);
if($rowcount>0){
$response['status'] = 1;
$response['message'] = 'Login successful';
}
else{
$response['status'] = 0;
$response['message'] = 'Invalid username of password';
}
echo json_encode($response);exit;
?>
提前致谢。