Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
登录服务可以';我看不懂php文件_Php_Angularjs - Fatal编程技术网

登录服务可以';我看不懂php文件

登录服务可以';我看不懂php文件,php,angularjs,Php,Angularjs,我的angularjs登录服务似乎无法读取我的登录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

我的angularjs登录服务似乎无法读取我的登录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";
}
?>
这是我的登录标记

 <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>

用户名
密码

在login.php中,无论用户是否经过身份验证,您都在设置$\u会话['uid']

你需要像这样的东西:

$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {  //found an authenticated user
   session_start();
   $_SESSION['uid'] = uniqid('auth_');
   //print $_SESSION['uid'];
   //now redirect to the first authenticated page of your site
   header("Location: nextPage.php");  //or you can do a url 
   exit;
} else { //user wasn't found
//user wasn't found and present error message or error message page
}

注意:在nextPage.php开始时,您应该检查设置的会话,如果无效(即不是偶然浏览该会话的有效用户),则将该用户发送到其他地方,或者至少阻止脚本的其余部分运行。

您的登录php文件实际做了什么,除了查询用户表而不处理结果之外,我的php文件的工作只是检查与用户输入的用户名和密码匹配的现有数据。如果有,那么用户可以访问主页。检查是否从上面的代码粘贴中排除,或者尚未实现?因为上面的代码片段似乎没有任何用途,除了创建一个会话而不考虑用户输入。请查看我的更新代码。。是的,这是一个改进@jean,您可能需要更新您的登录服务文件,因为它只是检查是否有来自ajax调用的响应,以及php脚本是否在错误登录时返回“否”,这仍然是一个回答:)代码用于阻止具有错误凭据的用户,但是..它不允许我现在登录成功后,您需要将有效用户重定向到站点的打开页面。我已经编辑了上面的答案。好的,但成功后重定向应该是我的登录服务文件的工作。顺便说一下,php文件无法识别我输入的正确凭据,它会直接转到其他条件w/c为echo“no”嗨,你想在login.php文件中实现什么?它最初的读取方式是,获取用户和密码,对照数据库进行检查,然后设置会话。在这种情况下,假设凭证在db中,则不需要登录服务,只需将html页面的form action设置为login.php
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {  //found an authenticated user
   session_start();
   $_SESSION['uid'] = uniqid('auth_');
   //print $_SESSION['uid'];
   //now redirect to the first authenticated page of your site
   header("Location: nextPage.php");  //or you can do a url 
   exit;
} else { //user wasn't found
//user wasn't found and present error message or error message page
}