【发布时间】:2017-10-30 17:16:43
【问题描述】:
我尝试使用 angualrJS 和 php 进行身份验证。我通过console.log对其进行了测试,当密码不正确时,我收到错误消息,而当密码正确时,我什么也没有得到,在这种情况下,我想被骑到其他视图,请问我该怎么做:
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';
console.log(data);
})
.error(function(data, status, headers, config)
{
console.log('error');
});
}
});
登录.php
<?php
$data = json_decode(file_get_contents("php://input"));
$connect = mysqli_connect("localhost", "root", "", "test");
if(count($data) > 0)
{
$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.'"';
$q = mysqli_query($connect , $query);
if(mysqli_num_rows($q) > 0 )
{
$_SESSION["logged_in"] = true;
$_SESSION["naam"] = $NomClient;
}
else
{
echo 'The username or password are incorrect!';
}
}
?>
如你所见,我在 app.js 中有一行注释: // $window.location.href = '#/admin';我把它作为评论,因为当我放它时,它会将我重定向到管理员视图但是密码不正确。
提前致谢
【问题讨论】:
标签: php angularjs ionic-framework