这个会话代码我做错了什么?
What am I doing wrong with this session code?
我正在尝试使页面无法访问,除非用户具有特定的权限级别并且是系统的用户。
我在下面提供了我的代码。
<?php
session_start();
include 'login/config.php';
if($_SESSION['username']=='user' && $_SESSION['permissionlevel']!='one');{
echo "<script>you dont have permission to access this page</script>";
header:("location:dashboard.php");
}
?>
我的代码哪里出错了?
编辑:
在 Neelesh 的帮助下修改了代码,但它仍然无法正常工作。
我认为您正在搜索 ACL 实施或其工作原理。 Zend Framework 对此有很好的实现。看这里:http://framework.zend.com/manual/current/en/modules/zend.permissions.acl.intro.html它是如何工作的。
问候
如果假设您有管理员和用户等用户角色
以及一级、二级和三级权限
根据此用户角色和权限级别,如果您在登录时将它们转换为会话,您可以检查该页面
if($_SESSION['USERROLE']=='USER' && $_SESSION['PERMISSIONLEVEL']!='THREE')
{
echo "<script>you dont have permission to access this page</script>";
header:("location:index.php")
}
通过这个简单的检查,如果不通过警告消息将他重定向到主页,您可以授予对特定页面的访问权限
我正在尝试使页面无法访问,除非用户具有特定的权限级别并且是系统的用户。
我在下面提供了我的代码。
<?php
session_start();
include 'login/config.php';
if($_SESSION['username']=='user' && $_SESSION['permissionlevel']!='one');{
echo "<script>you dont have permission to access this page</script>";
header:("location:dashboard.php");
}
?>
我的代码哪里出错了?
编辑:
在 Neelesh 的帮助下修改了代码,但它仍然无法正常工作。
我认为您正在搜索 ACL 实施或其工作原理。 Zend Framework 对此有很好的实现。看这里:http://framework.zend.com/manual/current/en/modules/zend.permissions.acl.intro.html它是如何工作的。
问候
如果假设您有管理员和用户等用户角色
以及一级、二级和三级权限
根据此用户角色和权限级别,如果您在登录时将它们转换为会话,您可以检查该页面
if($_SESSION['USERROLE']=='USER' && $_SESSION['PERMISSIONLEVEL']!='THREE')
{
echo "<script>you dont have permission to access this page</script>";
header:("location:index.php")
}
通过这个简单的检查,如果不通过警告消息将他重定向到主页,您可以授予对特定页面的访问权限