我的angularjs登录服务似乎无法读取我的登录php文件,因为它允许用户使用错误的凭据进行日志记录。请帮帮我。提前致谢。登录服务似乎无法读取php文件
这是我的登陆PHP文件
<?php
$con = mysqli_connect("localhost","root","");
mysqli_select_db($con, "motor_pool");
$user = json_decode(file_get_contents("php://input"));
$Username = mysqli_real_escape_string($con, $user->Username);
$Password = mysqli_real_escape_string($con, md5($user->Password));
$sql = "SELECT * FROM users WHERE Username='$Username' AND
Password='$Password'";
$result = mysqli_query($con, $sql);
if(mysqli_num_rows($result) > 0){
session_start();
$_SESSION['uid'] = uniqid('auth_');
print $_SESSION['uid'];
}else {
echo "no";
}
?>
,这是我的登录服务文件
'use strict';
angular.module('motorApp')
.factory('loginService', ['$http', '$location', 'sessionService',
function($http, $location, sessionService) {
return {
login: function(data, scope) {
var $promise = $http.post('database/login.php', data);
$promise.then(function(msg) {
var uid = msg.data;
if(uid) {
sessionService.set('uid', uid);
$location.path('/dashboard');
} else {
$scope.msgtxt = 'incorrect info';
$location.path('/login');
}
});
}
}
}
]);
这是我的登录标记
<div class="w3-group">
<label class="w3-label w3-text-black">User Name</label>
<input class="w3-input w3-border w3-round" type="text" style="width:100%" name="Username" ng-model="user.Username" required="">
</div>
<div class="w3-group">
<label class="w3-label w3-text-black">Password</label>
<input class="w3-input w3-border w3-round" name="Password" type="password" style="width:100%" required="" ng-model="user.Password">
</div>
<div class="w3-center">
<input type="button" name="button" class="w3-btn-block w3-red btnlog" ng-click="login(user)" value="LOGIN">
</div>
你的登录php文件实际上做了什么,除了查询用户表并且没有对结果做任何事情? – flauntster
我的php文件的工作就是检查一个与用户输入的用户名和密码相匹配的现有数据。如果有,那么用户可以访问主页 – jean
是检查从上面粘贴的代码中排除的位还是尚未实现?因为上面的代码片段似乎没有任何用处,除了创建会话而不管用户输入。 – flauntster