Forum Moderators: coopster
Is this a good approach or are there better/other ways to check that the user "subscribe"/is autorized to view a file?
Thanks in advanced!
/Claes
So when someone logs in, you generate the tabs with PHP (I'm partial to using templates) and you would
select tab from tabJoinTable where role = '{$_SESSION['userRole']}'
That's assuming you have their role in a session variable.
Please note that even though I had text representations of the roles, when I stored them in session variables I kept them hashed so someone couldn't spoof a role by changing the session variable they pass to another text representation. Now even though you don't display the tabs, they still my try to access a page by some other way. For this, you need a table with the roles and pages
ie
id ¦ role ¦ page
1 ¦ regular admin ¦ somepage.php
1 ¦ regular admin ¦ somepage2.php
Then just include this function in every page.
function checkPermission(){
//you would need the code to get the current
//user's role here
//you would need to get the current page url here
//then do something like
//select count(*) from userPermissionTable where role = '{$userRole}' and page = '{$currentUrl}';
//loop through that and do an if to see if it returns a row
//if it does return true otherwise set the header to
//redirect to a permissions error page.
}//function
Hope that helps.