Forums

How do I add permission checking to access the form?

batmon 14 Mar, 2009
Hi,

I created a form and need to make it with restricted access. I guess the easiest method I can think of is to retrieve user's login ID, if ID=3 ,4 ,5 or 6, user can access; if not, kick user to a different page.

How do I do this? Thank you.
nml375 14 Mar, 2009
There are a few examples around in the forum.

Something to get you started though:
<?
$user =& JFactory::getUser();
if ($user->id != 0) {
//User logged in, lets show the form...
?><input type.....

...
<? } else {
//Not a logged on user, redirect to frontpage
$site =& JFactory::getApplication('site');
$site->redirect(HTTP::_('/index.php'));

//We could of course just show some fancy text here instead, letting the visitor know (s)he lacks access...
} ?>

You could also extend this to check for certain group memberships using $user->gid.
For more advanced rights management, there's always the JAutorization-class.
This topic is locked and no more replies can be posted.