自从我阅读有关身份验证的教程和问题已经一个多星期了,但徒劳无功。我已经多次提出这个问题,并且每次我继续改变代码,但是我找不到解决方案。使用angularJS和php的简单身份验证
我想在我的应用程序中有一个简单的身份验证,保持与我工作的代码相同的结构。这是我的HTML文件:
的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, $location,$state,$http,$window){
$scope.submit = function()
{
data = {
'NomClient' : $scope.NomClient,
'mdp' : $scope.mdp
};
$http.post('http://localhost/deb/login.php', data)
.success(function(data, status, headers, config)
{
$window.location.href = '#/admin';
})
.error(function(data, status, headers, config)
{
console.log('error');
});
}
});
的login.php
<?php
$data = json_decode(file_get_contents("php://input"));
$connect = mysqli_connect("localhost", "root", "", "test");
$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_num_rows($query) > 0)
{
$_SESSION["logged_in"] = true;
$_SESSION["naam"] = $NomClient;
}
else
{
echo 'The username or password are incorrect!';
}
?>
此代码不起作用,因为它不不检查密码和用户名,它总是将我重定向到管理员视图。
在此先感谢
是否有在控制台的任何错误? – Jigarb1992
在控制台中没有错误,但是当我独立执行login.php文件时,我得到NomClient的未定义索引和mdp – SalamSalam
您可以通过最后一段代码的颜色格式来判断SQL中引号存在问题。 –