User Permissions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bedcor
Forum Newbie
Posts: 24
Joined: Fri Jul 26, 2002 11:01 am
Location: Barrie, Ontario

User Permissions

Post by bedcor »

How do i go about setting permissions for those who login and for those users that are registered?
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post by llimllib »

One easy way is to add a field to the user database called "permissions", and keep its value as a session var once the user's logged in. Then, just check if they have the correct permission when they try to access a page. Maybe 'A' could be all permissions and 'Z' none.
bedcor
Forum Newbie
Posts: 24
Joined: Fri Jul 26, 2002 11:01 am
Location: Barrie, Ontario

Post by bedcor »

Sorry, i realize that i didn't explain myself clearly enough?

What i want to happen is that when a user logs in they are redirected to another form based on their permissions. For example some users will be able to add/edit/update/delete/view records from the database whereas others will only have add/view permissions.

Hope this is more clear! :)
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post by llimllib »

$query = "SELECT permissions FROM users WHERE user=$username";
$result = mysql_query($query);
$row = mysql_fetch_row($result);

switch($row) {
case 'A':
header('admin.php');
case 'B':
header('employee.php');
case 'C':
header('user.php');
}

<edit>those should all be 'header("Location:' whatever.php
i.e. header('Location:user.php');</edit>
Last edited by llimllib on Wed Jul 31, 2002 2:20 pm, edited 2 times in total.
bedcor
Forum Newbie
Posts: 24
Joined: Fri Jul 26, 2002 11:01 am
Location: Barrie, Ontario

Post by bedcor »

The only question i have about this now is, the code you gave is great, but who determines what access they get when they first login? and who updates there permission and what is that update based on?
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post by llimllib »

Question a: you decide
Question b: you decide
Question c: you decide

Really, it's all up to you. Whenever, however, and whomever you choose can change those permissions. Hell, you could give a random permission at each logon. You could institute a moderation system. You could do anything you wanted to with that field in the database.
bedcor
Forum Newbie
Posts: 24
Joined: Fri Jul 26, 2002 11:01 am
Location: Barrie, Ontario

Post by bedcor »

first , how do you set it up randomly? and second, how do you know you can trust the users that get the random permission of full control?
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post by llimllib »

Well, actually setting up random permissions would probably not be very intelligent for the welfare of your site. It was meant as a joke.
Secondly, try some code, dude. The only way to learn this stuff is to try and write some for hours on end. Read tutorials. Read about the mt_rand() function. read about mysql and about sql in general. DO SOME WORK! it'll be fun, I promise.
bedcor
Forum Newbie
Posts: 24
Joined: Fri Jul 26, 2002 11:01 am
Location: Barrie, Ontario

Post by bedcor »

thanks for listening llimllib :D

I'm off to do some reading and work, hopefully without banging my head off the wall!

Again much abliged!
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post by llimllib »

nah problem, bedcor. good luck.
Post Reply