javascript - restricting access to specific users in php error
问题描述
I have a made a simple website with login. My users sql table is as shown below:
my login form is like below:
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="login-panel panel panel-success">
<div class="panel-heading">
<h3 class="panel-title">Sign In</h3>
</div>
<div class="panel-body">
<form role="form" method="post" action="login.php">
<fieldset>
<div class="form-group" >
<input class="form-control" placeholder="E-mail" name="email" type="email" autofocus>
</div>
<div class="form-group">
<input class="form-control" placeholder="Password" name="pass" type="password" value="">
</div>
<input type="submit" value="login" name="login" >
i want to restrict some users from entering some pages. i have made the access column for this. I have added the following code to the protected page
session_start();
if($_SESSION["access"]!=0)
{
header('Location: login.php');
}
there are some problems with this coode i guess. when the access=0,the page is shown even if the user is not logged in and shows like Undefined index: access in C:\xampp\htdocs\nurse\index.php on line 12
when the access is set to 1 ,its redirected to login page. can anyone help me?
解决方案
您需要检查会话是否设置为这样
if(isset($_SESSION["access"])) {
if($_SESSION["access"] !=0) {
header('Location: login.php');
}
}
推荐阅读
- reactjs - React 模型打开时滚动到底部
- c# - 将 C# dll 与 G-WAN 一起使用
- powershell - 在启用代理的情况下为 Windows Server 扫描 AD
- r - RStudio 打开后立即冻结
- postgresql - 在 PITR 之后 recovery.conf 没有更改为 recovery.done
- java - 无法在嵌入的 Eclipse Tomcat 上运行 Spring Boot 应用程序
- php - 来自 AJAX 请求的 CodeIgniter 中的表单验证失败
- java - 将 Saxon 与 Xalan 一起使用
- python - AWS Lambda Python3如何返回字符串而不是二进制(默认)CJK问题
- python - 通过电子邮件发送变量,看不到整个列表