jlhaslip
Feb 28 2008, 02:01 AM
There have been several recent request for methods to restrict access to various pages on a web-site based on User Permissions in sites that have a Login System in place. Here is some code showing one method to restrict access by providing a sub-set of your site's links based on the User's permissions. In this demonstration, I have defined a string for each 'level of user' determining which set(s) of links they can view on your site. Normal MySql procedure would be to read the User's permission level from a record in the database. For the purpose of this demonstration, an array is constructed. The output reflects the various combinations of their permissions. The strings are a series of concatenated Boolean values for the permissions allowed by a group. 0 = false (no links) 1 = true (links). As you can see, the Guests get 'some' links, Members get 'some more' links, Mods get 'still more', and the Admins get 'all' links. Array values can be read from the User Profile or from $_SESSION values, or from a 'group' table depending on their group membership. Each member is assigned to a Group and their permissions are given according to the Group they belong to. Whether the permissions string is stored with the member Profile ( not suggested ) or in a separate Table in the database ( suggested ) does not really affect the function of this procedure, as long as the permissions function is fed the correct of string. Replace these simple echo commands with the code which will generate the links for your site. And normally, you would not use the else statements, so those could be removed from the code, too. Adjust the details and particular to suit your own needs. Additional Permissions could be set for allowing certain Groups the right to add, edit, delete stuff, or Ban Users, etc. I'll leave that to you, since it would be very site specific. Happy Coding.  CODE $levels = array( 'Guests' => "1000" , 'Users' => "1100", 'Mods' => "1110" , 'Admins' => "1111" , );
/* *Function to assign Permissions based on Group membership */ function permission( $p ) { // Split the levels string into an array $perm = str_split( $p ); // Permissions array $up = array( 'can_view_links_1' => 1, 'can_view_links_2' => 2, 'can_view_links_3' => 3, 'can_view_links_4' => 4, ); $combine = array_combine( array_keys( $up ), $perm ); return $combine; }
/* * Procedure Test Printing */
foreach ( $levels as $i => $value) {
/* print Group name here */ echo '<h3>' . $i . '</h3>' ; /* call function to assign permissions */ $p = permission( $levels[$i] ); /* check Guest permissions */ if( $p['can_view_links_1'] == 1 ){ echo 'can view Guest links ' . $p['can_view_links_1'] . '<br />'; } else { echo 'no links here ' . $p['can_view_links_1'] . '<br />'; }
/* check Member permissions */ if( $p['can_view_links_2'] == 1 ){ echo 'can view Member links ' . $p['can_view_links_2'] . '<br />'; } else { echo 'no links here ' . $p['can_view_links_2'] . '<br />'; } /* check Moderator permissions */ if( $p['can_view_links_3'] == 1 ){ echo 'can view Moderator links ' . $p['can_view_links_3'] . '<br />'; } else { echo 'no links here ' . $p['can_view_links_3'] . '<br />'; }
/* check Administrator permissions */ if( $p['can_view_links_4'] == 1 ){ echo 'can view Admin links ' . $p['can_view_links_4'] . '<br />'; } else { echo 'no links here ' . $p['can_view_links_4'] . '<br />'; } }
?>
Here is a demo using the above script. http://www.jlhaslip.trap17.com/permissions/Any questions, post them up here.
Reply
hippiman
Feb 29 2008, 11:32 PM
A couple of friends and I just did a programming competition using PHP and we just used a cookie with 3 values, for the different kinds of users. We didn't make it so that it didn't show the links, though. We just made each page show a thing saying that they don't have permission to use that page. I think what you're doing makes sense, too, though. I think you should also have each page deny access for if they just type in the right url, though. Nice tutorial.
Reply
jlhaslip
Feb 29 2008, 11:43 PM
Thanks. The site checks Sessions and Permissions both to deny access. I'll post the full version later as I complete the package. Might take a few days/weeks since it is a hobby, not a job.
Reply
alex1985
Mar 7 2008, 03:36 PM
For instance, if I have a simple login system with control panel. Can I merge this permission script with my login system or not? Write the tutorials as well as if you can.
Reply
Recent Queries:--
php users permission levels - 3.90 hr back. (1)
-
php user permissions updated by - 15.10 hr back. (1)
-
xp set special permission to restrict account - 18.29 hr back. (1)
-
php login with welcome page based on permission - 28.31 hr back. (1)
-
find php user permissions - 28.55 hr back. (1)
-
user add permission at database on php code - 30.18 hr back. (1)
-
program permission functions - 32.68 hr back. (2)
-
php user permission system - 48.92 hr back. (1)
-
php user permissions - 78.60 hr back. (1)
-
php two levels permissions - 103.08 hr back. (1)
-
php login with user permissions mysql - 107.12 hr back. (1)
-
php user group permission level - 126.24 hr back. (2)
-
permission system using numbers php - 134.36 hr back. (1)
-
php function windows user login - 134.54 hr back. (1)
Similar Topics
Keywords : user, permission, function, php, determining, user, permissions
- Php - Forms, Date And Include
Working with POST and GET and also the Date() function (0)
Php - Randomize Web Title
using arrays and the random function (5) PHP - Randomize Web Title with the rand function... Define the variables numbers we start at number
0 CODE $title = "Web title 0"; // Title 0 $title = "Web title 1"; // Title 1 $title =
"Web title 2"; // Title 2 $title = "Web title 3"; // Title 3 $title = "Web title 4"; // Title 4
?> now we use the rand() function to get a randomize the web title. rand(0, 4) means we start at
0 and end at 4 i can get 0,1,2,3,4 one of those. It depends how many arrays you have CODE //
get a random number $randomize = rand(0, 4); // Change four to how many arr....
Simple User System
php, mysql driven (19) Hey! Maybe you've seen my other tutorials...or my signature.. Anyways I'm going to show you
how to make a system so users of your site could register accounts and you could have protected -
user only - pages on your site /smile.gif" style="vertical-align:middle" emoid=":)" border="0"
alt="smile.gif" /> Ok, so we start by creating a config.php file. CODE $dbhost =
'database host'; $dbname = 'database name'; $dbusername = 'database
username'; $dbuserpass = 'database password'; mysql_connec....
*nix File Permissions - An Overview
(6) I was originally going to post this in a reply, but felt it would deviate from the topic.
Here's a brief overview of the three numbers in a permission "code": -The first number is for
the owner of the file. If you set a file at 600, the owner will have read and write access and
everyone else is locked out. -The second number is for the users group (users are placed into groups
to get special rights sometimes). Generally you will not give write access to a user's group.
-The third number is for the rest of the world, including web users. Setting any value that wi....
How To "lock Down" A Os X User Account
Crude but effective way to maintain Macs (1) Here's a quick summary of how one can configure OS X for use in public labs running Panther
(10.3). It should also work with Tiger (10.4) but I dunno. There may be better ways, but this is
quick and cheap: 1. Install OS X fresh, or boot up your new Mac, and set the username to
MacAdmin or the like. This is now the administrator account which users should never touch.
Share this password only with trusted admins authorized to muck with critical systems. 2.
Install all the software you expect anyone to need in the default folders (usually Applicat....
Hiding User Account On Xp
(0) Hopefully someone will find this useful. Ive done this on my machine as well. To a hide an account
to display on the welcome screen of xp here is a nifty way: 1. Open regedit 2. Browse to
Hkey_local_machine> software>microsoft>windows nt>winlogon>special Accounts>Userlist Here you will
see a list of all accounts on XP which are hidden and dont display on welcome screen. Yes XP does
create useless accounts as you see there. 3. Go on the right pane, right click, create a new dword
value with its name as the exact username you want to hide and its value as "0" without t....
How To: Change An Image When A User Clicks On It
using both php and javascript (11) How To: Change An Image When A User Clicks On It using both php and javascript - a powerful
combination I have seen quite a few how tos offering a method of doing this but none of which
resembled my method of making use of both php and javascript. This code is fairly repetitive and
most of the functions are easy to pick-up if you haven't heard of them before. Here it is...
Create your two images. Call them anything you like, you'd just need to change their filenames
in $imgano $imgayes. In fact with this script you can easily create more than one pair....
Simple Login In Visual Basic 6
user interaction example trough login programm (7) First of all, I am NOT a programmer, this is something my friend taught me. It describes basic
interaction with the user, while showing basic functionality of this simple programm. So, without
further ado, we're off to the tutorial: First of all, start your visual basic, when prompted
for new project, select Standard Exe . Next, we need to open code window, so we can start typing
the program. This can be done in two ways, one is double clicking on the form, or selecting Code
from View menu. If you double clicked on the form, you will see following text: CODE ....
Php Sockets
Introduction to an underused function of PHP (4) This tutorial is based on a question written in the PHP programming board Inspiration
Introduction Sockets, an underused function in PHP, is a function that enables you to open
connection to other peoples computers and vice versa. By sending commands to the operating server,
it will first see if there's response, then, it sends or receives data that the operating server
has available. Creation of a socket Of course, a first step in using sockets, is creating it,
this is done by: CODE resource socket_create ( int domain, int type, int protocol) and a ....
Using The Date() Function [php]
(2) The date() function can be used in a good way, in some cases, and the most common place you would
probably see this in use would be on forums. Let's get down to business... If you would like to
display the date, you would have to put the echo tag before the date() function as so... CODE
echo date("g:i:s"); Which would display as the common hours, minutes, seconds format (ex:
3:32:45). But you can also add wheather it is AM or PM, display the day (Sunday thru Monday), the
year, pretty much anything that has to do with date. Here is a chart to explain what e....
[tutorial] Delphi
Multi-Parsing Function (0) I've spent a while trying to create parsing function with Delphi. This language is very useful.
This tutorial explains how to parse multiple instances of an item in one string. Here is the
function (which I am actually very proud of): Code: function TForm1.MultiParse(MainString,
BeginString, EndString: string): TStrings; var PosBeginString, PosEndString, i, LastPos: integer;
tmpCopy: string; tmpStrings: TStrings; begin tmpStrings := TStringList.Create; LastPos := 0;
for i := 1 to LastDelimiter(EndString, MainString) do begin PosBeginString := Pos....
Delphi
Simple Text Parsing Function (1) Because parsing is such an integral part of string manipulation, I took the time to make a quick and
simple parse function. For you VBers, Delphi is a derivative of Pascal...it's powerful, simple,
and (best of all) doesn't need external component (eg: ocx files). Hence the code: Code:
function TForm1.SimpleParse(MainString, BeginString, EndString: string): string; var PosBeginString:
integer; PosEndString: integer; begin PosBeginString := Pos(BeginString, MainString) +
Length(BeginString); PosEndString := Pos(EndString, MainString); Result := Copy(MainString, ....
Looking for user, permission, function, php, determining, user, permissions
|
*SIMILAR VIDEOS*
Searching Video's for user, permission, function, php, determining, user, permissions
*MORE FROM TRAP17.COM*
|
advertisement
|
|