简体   繁体   English

PHP-使用用户个人资料保护用户权限

[英]PHP - Secure user permissions with user profile

I'm currently building a website for myself. 我目前正在为自己建立一个网站。 I'm looking to restrict certain aspects to the public so that when a user becomes a member they have "full" access. 我希望将某些方面限制为公开,以便用户成为会员时,他们具有“完全”访问权限。

The plan is to have a members area (for the general public) which will also allow the user to have a unique profile to which they can edit (such as profile picture etc) Currently I've set up a member login, and it does direct the user to a "members area" the problem being permissions. 该计划是要有一个会员区(面向普通公众),这还将允许用户拥有一个可以编辑的唯一个人资料 (例如个人资料图片等)。目前,我已经设置了一个会员登录名,将用户定向到“成员区域”,即权限问题。 At the moment, if someone was to browse to this "members area" using the url, they can go straight to it. 目前,如果有人要使用URL浏览到此“成员区域”,则他们可以直接进入该区域。 So Permissions is a big issue I'm struggling with. 因此, 权限是我一直在努力解决的一个大问题。 Along with the user them-self having a unique page to which they can edit their details of themselves. 他们与用户一起拥有一个独特的页面,他们可以在其中编辑自己的详细信息。

I also intend on having a Company area (company login already created in same way as member login), to which after a member has left a review of a type of job they received from the company this shows on the company profile to which they are able to respond to it if they wish. 我还打算在“公司”区域(已经以与成员登录相同的方式创建了公司登录),在成员对他们从公司收到的工作类型进行审核之后,该区域会显示在他们所在的公司资料中如果他们愿意的话,能够做出回应。

TL:DR - Members area permissions to restrict non-users from seeing certain aspects of the website. TL:DR-会员区域权限,用于限制非用户查看网站的某些内容。 A member unique profile. 成员唯一的个人资料。 Company profile. 公司简介。

Has anyone any good tutorials or tips for designing this sort of thing? 有没有人为设计这种东西提供任何好的教程或技巧?

Any help is greatly appreciated. 任何帮助是极大的赞赏。

Thanks, Andrew 谢谢,安德鲁

You can use SESSIONS Variables SESSIONS 您可以使用SESSIONS变量SESSIONS

Every time a user login you start a session and you store inside the session variables the details you need to check permissions (for example the type of the user) the session variables will be accessible from any page after that 每次用户登录时,您启动会话并在会话变量中存储检查权限所需的详细信息(例如用户类型)之后,都可以从任何页面访问会话变量

So in every page you can check if the session variable is setup that mean the user is logged in 因此,您可以在每个页面中检查是否设置了会话变量,这意味着用户已登录

Example

session_start();
$_SESSION["level"] = 1;
if ($_SESSION["level"] == 1) do your thing

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM