angularjs php 登陆,javascript – 即使AngularJS和PHP的凭据不正确,登录仍然会指向

PHP代码需要从表中获取数据,将其解码为JSON,然后将其发送到AngularJS.

如果登录凭据正确,Angular JS会重定向.

但是,即使凭据不正确,仍然会重定向用户(true语句始终通过).

PHP代码:

$data = json_decode(file_get_contents("php://input"));

$username = $data->username;

$password = $data->password;

/*

* Collect all Details from Angular HTTP Request.

*/ require_once("connection.php");

//must read from table

$connection = connectToMySQL();

//complete from here

$query = "SELECT count(*) FROM tbl_admin WHERE username = '$username' AND password = '$password'";

$result = mysqli_query($connection ,$query);

$row = mysqli_fetch_row($result);

$count = $row[0];

if($count == 1)

{

echo true;

}

else

{

echo false;

}

?>

AngularJS控制器:

app.controller('loginCtrl', function ($scope, $http, $location) {

/*

* This method will be called on click event of button.

* Here we will read the email and password value and call our PHP file.

*/

$scope.checkCredentials = function (credentials) {

$http.post('model/getAdmin.php',credentials).success(function(data){

console.log("true");

$location.path("/memberList");

})

.error(function(err){

$log.error(err);

console.log("false");

});

}

});

HTML表单代码

Username

Password

Submit

{{responseMessage}}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值