... - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › ... (1716 Views)
| ... by Codedreamer(op): 4:47pm On Nov 22, 2020*. Modified: 3:05pm On Apr 19, 2025 |
... |
| Re: ... by 404Dev: 6:14pm On Nov 22, 2020 |
Codedreamer:Am guessing you are storing the user id or user name of logged in user in a session variable. So, go to your users table in db and create a column is_admin with default value of 0. 0 indicates not admin while 1 indicates admin. So in the page you want to restrict, grab the user I'd from session, run a query to check if is_admin, proceed if so or redirect if necessary. |
| Re: ... by Karleb(m): 6:23pm On Nov 22, 2020 |
Codedreamer:Another way to go about it is to create a user_type column in the users table. user_type will be an enum data type with options like (user, admin, moderator, site_owner...). So you'll check, if $user->user_type === "admin". Preferably, the check should be in a middleware. |
| Re: ... by Codedreamer(op): 6:26pm On Nov 22, 2020*. Modified: 3:06pm On Apr 19, 2025 |
.. |
| Re: ... by Codedreamer(op): 6:30pm On Nov 22, 2020*. Modified: 3:06pm On Apr 19, 2025 |
... |
| Re: ... by stanliwise(m): 6:33pm On Nov 22, 2020 |
Codedreamer:Hello simply add a user role field and store as student admin or anything you like Simply check the role and then give access |
| Re: ... by Karleb(m): 6:42pm On Nov 22, 2020 |
Codedreamer:This should do it. It seems you are not working with routes, middlewares and the likes. It's better you check for the opposite though. Something like... If (! $admin){ //redirect to other page } Then you continue with the dashboard.php codes. The check should be the first thing in the dashboard.php file. A friendly advice. If you need to combine html and Php codes for any reason, especially for a project, consider using php templates. They are specifically made for this reason. |
| Re: ... by Codedreamer(op): 6:57pm On Nov 22, 2020*. Modified: 3:06pm On Apr 19, 2025 |
... |
| Re: ... by talk2hb1(m): 10:57am On Nov 23, 2020 |
Codedreamer:Google and read up on Role based access control, just my little Cent ![]() |
| Re: ... by Thenaijaitguy: 6:47pm On Nov 23, 2020 |
| Re: ... by niel63(m): 1:43am On Mar 03, 2022 |
Karleb:This seems like an approach I'll rather use though. Nice. The answer before this can do this too but I prefer this instead sha. |
| Re: ... by Franzee(m): 4:12am On Mar 10, 2022 |
Codedreamer:Tendency of loading only the else condition when you have like three user role... like Admin, Manager, Cashier... is high in your case you would have student, parents, teachers... so it's better to use $_SESSION['role']. .. And For security purposes, so even if a user types in the web address direct on the browser it would end $_SESSION immediately $_SESSION['role'] |
Top 5 Website To Access Or Download The Best Online Courses For Free • Web Development/php Help Center • How Can I Access A Website Running On Ipv6 Protocol • 2 • 3 • 4
My Best Web-work So Far, What Do You Think? • [Help Request] Abeg I Need Somebody That Knows Visual Basic Quiet Well • Java Control Panel Not Responding On Window 8.1
