showing tabs based on user permission - Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Webmaster Tech > Programming > PHP Development

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-11-2011, 04:26 PM   #1 (permalink)
Junior Member
 
Join Date: Jun 2011
Posts: 2
Default showing tabs based on user permission

Hi everyone,

I am creating a web app, I am using HTML with a css style sheet with php and mysql for the database stuff.
I have created a page with tabs across the top using the <li> tag, what I want to do is have only certain tabs available to certain users that login.

The way I am thinking of doing this is with a field in the mysql database with type of ENUM to represent different permission levels and when a user logins I will select * where the username equals the posted username and depending on what it returns I will then display certain tabs.

But I dont know how to stop it displaying tabs, can anyone point me in the right direction?

sorry If I dont make much sense, I come from a network admin background, web development is a whole new world for me
Thanks for any help
Eyeball is offline   Reply With Quote
Sponsored Links
Old 06-14-2011, 02:41 PM   #2 (permalink)
Junior Member
 
Join Date: Jun 2011
Posts: 1
Default Re: showing tabs based on user permission

If you just want something real simple, you can make a permissions table and then in your users table make a user_permissions column. In the permissions table, have an id column and an action column. The id column will just be an auto-incremented id, and the action column will be what you want the permission to be (for example, view_members_only_area, whatever).

Then in your users table, the user_permissions column will be a serialized array containing the id's of all of the permissions you want that user to have from the permissions table.

Then use this function to determine if they have the appropriate permission to do X.
Code:
function has_permission($user_id, $action)
{
	$query = mysql_query("SELECT user_permissions FROM users WHERE user_id='" . $user_id . "'");
	
	$user = mysql_fetch_assoc($query);

	$perms = unserialize($user['user_permissions']);

	$query = mysql_query("SELECT perm_id, perm_action FROM permissions WHERE perm_action='" . $action . "'");

	if (mysql_num_rows($query) > 0) {
		$perm = mysql_fetch_assoc($query);

		if (in_array($perm_id, $user['user_permissions'])) {
			return true;
		}
	}
        

	return false;
}
Finally, you can just do a simple if conditional to see if the user has the appropriate permission.

Code:
if (has_permission($_SESSION['user_id'], 'view_members_only_area') {
	echo '<li><a href="#">Members only area</a></li>';
}
redixx is offline   Reply With Quote
Old 06-15-2011, 03:33 PM   #3 (permalink)
Junior Member
 
Join Date: Jun 2011
Posts: 2
Default Re: showing tabs based on user permission

Thank you redixx! That solution is so simple yet elegant, effectively echoing out the extra tab if the permissions are in place, genius!

sorry im easily impressed, but thanks again that is magic and it works a treat
Cheers!
Eyeball is offline   Reply With Quote
Old 06-17-2011, 12:54 AM   #4 (permalink)
Junior Member
 
danieljames123's Avatar
 
Join Date: May 2011
Posts: 72
Default Re: showing tabs based on user permission

It also help me because I also suffered from this kind of prob but when I was seeing it, I thought that it will help me and now I am free from this problem. Thanks a lot.

Php Development India
danieljames123 is offline   Reply With Quote
Old 06-17-2011, 06:45 AM   #5 (permalink)
Junior Member
 
Join Date: Jun 2011
Posts: 1
Default Re: showing tabs based on user permission

This layout is so stellar. How did you manage to make a blog that’s as smart as it is sleek? I’ve got to say, the layout alone made me come back to this blog again. But now that I’ve read what you’ve got to say, I’ve got to share it with the world!
faolennart is offline   Reply With Quote
Old 06-24-2011, 02:42 AM   #6 (permalink)
Regular User
 
jacqueline_davic's Avatar
 
Join Date: Jun 2011
Location: USA
Posts: 16
Default Re: showing tabs based on user permission

thank you so much for the post
jacqueline_davic is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 04:49 PM.


Powered by vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2
Webmaster Forums
Web Hosting | Chicago Web Hosting | Web Hosting