Javascript 用户授权/未授权访问的网页,并导致错误
我的页面是main.php,它是这样编写的Javascript 用户授权/未授权访问的网页,并导致错误,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我的页面是main.php,它是这样编写的 <?php include_once('createtables.php'); include('function.php'); ?> <!DOCTYPE html> <html lang="en"> <head> <title></title> <meta charset="utf-8"> <meta name="viewport" co
<?php
include_once('createtables.php');
include('function.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../includes/css/bootstrap.min.css">
<link rel="stylesheet" href="../includes/css/main.css">
<script src="../includes/js/jQuery.js"></script>
<script src="../includes/js/login.js"></script>
<script src="../includes/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<form id="lgform" action="checklogin.php" method="post">
<h4 class="text-primary" id="llc"><img src="../includes/img/chatballoon.png"> Network Chat </h4>
<div class="input-group" id="firstone">
<span class="input-group-addon">
<span class="glyphicon glyphicon-user"></span>
</span>
<input type="text" class="form-control" placeholder="Enter Account name" id="username" name="username" autofocus>
</div>
<div class="input-group" id="secondtwo">
<span class="input-group-addon" id="password-addon">
<span class="glyphicon glyphicon-lock"></span>
</span>
<input type="password" class="form-control" placeholder="Enter your password" aria-decribedby="password-addon" id="password" name="password" autofocus>
</div>
<a href="createaccount.php" id="signup">Create Account</a>
<input type="submit" class="pull-right btn btn-primary btn-sm" name="submit" id="submit" value="Enter now">
</form>
</div>
</body>
</html>
浏览器无法访问checklogin.php文件的问题。我想要的是避免未经授权的用户进入该页面,因为即使是登录用户,如果他们在browser register.php上键入,也会进入该页面并显示用户名错误等
这类错误:
您应该使用标准http状态代码401进行响应,以便浏览器知道无法加载页面:
if($count == 1){
...
} else {
header("HTTP/1.1 401 Unauthorized");
// or for php 5.4:
http_response_code(401);
}
更新:
对于以后添加的错误:
在访问$\u POST中的值之前,请检查它们是否存在:
if (isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
// ... all the rest of your code that depends on $_POST comes here
}
您应该使用标准http状态代码401进行响应,以便浏览器知道加载页面失败:
if($count == 1){
...
} else {
header("HTTP/1.1 401 Unauthorized");
// or for php 5.4:
http_response_code(401);
}
更新:
对于以后添加的错误:
在访问$\u POST中的值之前,请检查它们是否存在:
if (isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
// ... all the rest of your code that depends on $_POST comes here
}
您可以在check_登录脚本中添加一些检查,以查看URL是否匹配并将其回退
if(strpos($\u SERVER['REQUEST\u URI'],'register.php'))exit()
或类似的东西 您可以在check\u登录脚本中添加一些检查,以查看URL是否匹配并将其回退if(strpos($\u SERVER['REQUEST\u URI'],'register.php'))exit()
或类似的东西 如果用户已授权或未授权,请在此页面上添加检查。如果没有,则重定向到其他页面。即使授权用户能够查看此页面并在此页面上导致错误。我想要的是这个页面是不可查看的,如果表单提交给它,那么访问者浏览器将访问它,除非通过Ajax。所以,要做您在这里尝试的事情,他们仍然会访问页面……我将更新我对这个问题的假设,但是您的代码有经典sql注入的最佳示例。请参考此解决方法:如果用户已授权或未授权,请在此页面上添加检查。如果没有,则重定向到其他页面。即使授权用户能够查看此页面并在此页面上导致错误。我想要的是这个页面是不可查看的,如果表单提交给它,那么访问者浏览器将访问它,除非通过Ajax。所以,要做您在这里尝试的事情,他们仍然会访问页面……我将更新我对这个问题的假设,但是您的代码有经典sql注入的最佳示例。请参考这个来修复它:先生@Gavriel:你的帖子在某种程度上是有帮助的。但是当我已经登录了,然后尝试访问checklogin.php时,仍然会出现错误showssir@Gavriel:你的帖子在某种程度上是有用的。但当我已经登录,然后尝试访问checklogin.php,错误仍然显示