开发者

problem with access to specify pages for users

开发者 https://www.devze.com 2023-03-11 01:09 出处:网络
HI, i am writing and designing a website with php.in this site every want开发者_如何学运维 can register and admin can go to admin.php for manage the site.but my problem is that every one that type www

HI, i am writing and designing a website with php.in this site every want开发者_如何学运维 can register and admin can go to admin.php for manage the site.but my problem is that every one that type www.example/login/admin.php can access to admin.php.how can i prevent other users that can't access to admin page?


You probably want to look at .htaccess file. Check this link out


You have to do the login page for the admin.php. Only if the people with the correct username and password can see the admin page and do the admin action


How do you define terms like "user" and "admin" and what is the process for creating/registering an account?

Generally, you would associate "users" with "roles" in your database. If a user account is supposed to be an admin, you associate that user record with the admin role. If the user is a standard user, associate them with the standard user role (which may be the default by having no role, though I'm not a big fan of implicit knowledge vs. explicit definitions in software). Users should also be able to have multiple roles, in case you have various classes of "user" and they need to have overlapping privileges.

Then, in the admin section of the site, your code would check if the current logged-in user (however you track that, you didn't specify) is in a given role before rendering the page. If not, then either send the user to another page or display a message, etc.

If every user can access the admin page, then essentially every user is an admin. How do you distinguish one from another in the code or in the data? That's where you need to start.

0

精彩评论

暂无评论...
验证码 换一张
取 消