PHP管理员帐户

时间:2012-10-26 22:40:37

标签: php jquery html authentication user-accounts

在我的网站上,当有人使用管理员帐户登录时,我想要启用一些选项。我的问题是如何尽可能地保护该管理员帐户。他们在我的网站上设置登录是在验证登录后,我这样做$_SESSION['status'] = 'authorized';然后我说这样的话:

<script>
$(document).ready(function(e) {
    if(<?php echo ($_SESSION['status'] == 'authorized'); ?>) {
        $('#account_window').show();
    }
});
</script>

<div id="account_window">
    //account stuff
</div>

添加了主帐户我正在考虑添加此$_SESSION['master'] = 'authorized';,然后在首页中添加此代码:

<script>
$(document).ready(function(e) {
    if(<?php echo ($_SESSION['status'] == 'authorized'); ?>) {
        $('#account_window').show();
    }
});
</script>

<div id="account_window">
    //account stuff
    <?php if($_SESSION['master'] == 'authorized') { ?>
        <div id="master_account">
            //admin stuff like send users emails
        </div>
    <?php } ?>
</div>

但是我觉得这太简单了,这是一种安全的方法来验证主账号吗?如果没有,那么最好的方法是什么?

2 个答案:

答案 0 :(得分:5)

从非管理员那里“隐藏”管理界面可能很诱人,但如果有人只是将正确的HTML注入页面(例如使用GreaseMonkey脚本),或者手动生成请求,那么这基本上是可以绕过的。

您必须验证PHP中的每个操作才能获得任何实际的安全性。因此,您需要在用PHP提交任何表单或提交操作时检查用户是否已获得授权。

答案 1 :(得分:0)

您必须验证PHP中的每个操作才能获得任何实际的安全性。因此,您需要在用PHP提交任何表单或提交操作时检查用户是否已获得授权。