所以我知道一些 html、css、js、php 和 mysql,但我对安全问题的了解非常有限 对于我正在 build 的网站,我只是使用 css display:none (用 js 触发) 根据用户的类型(客户、员工、老板)显示或不显示某些内容。 我明白如果你不想让别人看到他应该 不(检查页面或其他方式)你根本不应该发送该信息(来自服务器端= php)。 我不确定我的想法是否正确。
如果我有 3 种类型的用户 1) 客户 2) 员工 3) 老板 我想显示不同的内容(基本上相同的内容,但更多信息 给员工,甚至更多给老板)给他们每个人网站中存在的 5 个页面是否有效 每个页面有 3 个不同的 php 文件(每个用户类型一个),在登录过程中为每个用户在 $_SESSION['authority'] 存储不同的值,并使用该值来决定他可以访问哪个页面?
例如,起始页面是 index.php,当用户根据他的权限级别(从数据库检索)登录时,他将是 使用 header("Location: name_of_page.php") 重定向如果他是客户,则为 index.php,如果他是雇员,则为 index_employee.php 如果他是老板,则到 index_boss.php。 并在每个页面中使用类似以下的内容来防止具有不同权限的用户进入。
index_boss.php
<?php
session_start();
if($_SESSION['authority'] == 2 && $_SESSION['loggedin'] == true) {
?>
page content
<?php
}
else
{
if( $_SESSION['authority'] == 1 )
{
header("Location: index_employee.php");
}
else
{
header("Location: index.php");
}
}
?>
这是解决这个问题的正确方法吗? 有没有办法只为所有用户使用 1 个 php 文件,并通过其他安全方式隐藏或显示某些内容?
最佳答案
是的,可以在同一页面中执行此操作!像这样做: 根据:1)老板 2)员工 3)客户 index.php
<html>// Start the session here
<?php session_start();?>
<head>
//Your configuration
</head>
<body>
<?php
if($_SESSION['authority'] == 1 && $_SESSION['loggedin'] == true) {
?>
Here the Contents of the boss
<?php
elseif($_SESSION['authority'] == 2 && $_SESSION['loggedin'] == true) {
;?>
Here the contents of employee
<?php }else{ ?>
Here the contents of clients
<?php };?>
</body>
</html>
关于javascript - 为每种类型的用户提供不同内容的网站(关于安全性),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48245969/