如何保护页面模式免受用户注入


How to secure page mode from user injection?

我有一个php表单页面(page.php)与3种不同的模式(插入/编辑/查看)

索引页(index.php)包含3个指向(page.php)的链接,每个链接将根据当前用户角色显示

index.php

<html>
<body>      
    <div id='main'>
        <a href="page.php?insertMode=true&editMode=true">Insert Student Screen</a> <br>
        <a href="page.php?insertMode=false&editMode=true">Edit Student Screen</a> <br>
        <a href="page.php?insertMode=false&editMode=false">View Student Screen</a> <br>
    </div>  
</body>
</html>

我的问题
用户既没有insertMode也没有editMode (insertMode=false&editMode=false)
可以更改URL中的值,然后
他将以一种他没有的模式打开page.php

此权限必须存储在数据库中…不在URL中。所以,当你在会话中加载你的用户时,你也加载了他的权限,可以很容易地检查他是否有编辑或插入的权利。

最好的方法是有一个表User,一个表Right(包含所有可用的权限)和一个关联这些表的表(如UserRights?),其中主键由User和Right的主键组成。这样,一个用户可以拥有多个权限。

你应该看看这个

http://www.singingeels.com/Articles/Understanding_SQL_Many_to_Many_Relationships.aspx