Page 1 of 1
User Permissions
Posted: Wed Jul 31, 2002 12:53 pm
by bedcor
How do i go about setting permissions for those who login and for those users that are registered?
Posted: Wed Jul 31, 2002 1:06 pm
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.
Posted: Wed Jul 31, 2002 1:16 pm
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!

Posted: Wed Jul 31, 2002 1:58 pm
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>
Posted: Wed Jul 31, 2002 2:11 pm
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?
Posted: Wed Jul 31, 2002 2:18 pm
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.
Posted: Wed Jul 31, 2002 2:32 pm
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?
Posted: Wed Jul 31, 2002 2:37 pm
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.
Posted: Wed Jul 31, 2002 2:47 pm
by bedcor
thanks for listening llimllib
I'm off to do some reading and work, hopefully without banging my head off the wall!
Again much abliged!
Posted: Wed Jul 31, 2002 2:56 pm
by llimllib
nah problem, bedcor. good luck.