阻止从用户 ID 访问用户个人资料页面

发布于 2024-12-04 19:39:03 字数 107 浏览 2 评论 0原文

我有一个用户个人资料页面,其网址如下: www.XXXXXXX.com/userid/45

当用户将 /userid/45 更改为 /userid/47 时,有没有办法阻止访问其他页面

i have a user profile page that have the following url : www.XXXXXXX.com/userid/45

is there a way to prevent access to other page when a user change /userid/45 to /userid/47

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

惜醉颜 2024-12-11 19:39:03

根据您使用的语言,用户个人资料页面上会显示如下内容:

if url_segment(2) != user_info['userid']
  render no_permission
end

Depending on the language you're using, something like this on the user profile page:

if url_segment(2) != user_info['userid']
  render no_permission
end
×纯※雪 2024-12-11 19:39:03

您可能想看一下 Zend_Acl。

http://framework.zend.com/manual/en/zend.acl .introduction.html

这将允许您根据发出请求的角色分配的权限来控制对某些资源(例如配置文件)的访问。您还可以使用断言指定更细粒度的访问。

因此,举例来说,您为在您的​​网站上注册的用户指定了一个“注册”角色,这些用户也将拥有一个个人资料页面。您的规则可能如下所示:-

“已注册”可以“显示”“个人资料”“如果这是他们的个人资料”。

角色:“注册”

权限:“显示”

资源:“个人资料”

断言:检查所有权的代码

You might want to take a look at Zend_Acl.

http://framework.zend.com/manual/en/zend.acl.introduction.html

This would allow you to control access to certain resources (e.g. a profile) based upon the assigned privileges of the role making the request. You can also specify more fine-grained access with assertions.

So, say for example, you specified an 'registered' role, for users registered with your site, who would also have a profile page. Your rule might read like this :-

'registered' can 'display' a 'profile' 'if it is their profile'.

Role: 'registered'

Privilege: 'display'

Resource: 'profile'

Assertion: code that checks for ownership

好菇凉咱不稀罕他 2024-12-11 19:39:03

我一直在 WordPress 中寻找这个,只有在发布我的答案后,我才意识到你在问 WordPress 以外的东西......哦,好吧,对于犯我同样错误的人来说,这是同样的事情,但对于 WordPress:

你可以修改此设置,通过将 == 更改为 != 并仅输入管理员 ID(通常为“1”),使其重定向所有用户,而不仅仅是一个用户。

add_action('admin_init', 'redirect_to_forum');
function redirect_to_forum(){
    $current_user=wp_get_current_user();

    if($current_user->user_id == "47"){
        header('Location: http://somewhereelse.com');
    }
}

I was looking for this in wordpress and only after posting my answer did I even realize you were asking about something other than wordpress... Oh well, for people who make my same mistake, here is the same thing, but for wordpress:

You can modify this to make it redirect all users instead of just one user by changing the == to != and enter just the admin id (usually "1").

add_action('admin_init', 'redirect_to_forum');
function redirect_to_forum(){
    $current_user=wp_get_current_user();

    if($current_user->user_id == "47"){
        header('Location: http://somewhereelse.com');
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文