I have a php site which has multiple php scripts. I need to provide users from another site limited access into my system. I want to restrict what pages these ppl can access.
I am doing this in the following manner:
// $_SESSION['systemid'] is set with a value of say, '1'
$permissionArray = $objACCESS->getPermissions($_SESSION['systemid']);
// getPermissions returns an array like the following (for that systemid):
// 0 => {'systemid' => '1', 'permission_type' => 'createcontent' }
// 1 => {'systemid' => '1', 'permission_type' => 'invitecontacts' }
// the following contain a list of script names that should be
// restricted if permission is not allowed
$createcontent = array('createcontent.php');
$managecontent = array('managecontent.php');
$invitecontacts = array('invitecontacts.php');
$page_name=basename($_SERVER["SCRIPT_FILENAME"]);
if(is_array($permissionarray))
{
$haspermissions = false;
foreach($permissionarray as $permissions)
{
if(in_array($page_name,${"$permissions[permission_type]"}))
{
$haspermissions = true;
break;
}
}
}
if($haspermissions==false)
{
// - do not have permissions
echo "<meta http-equiv=\"refresh\" content=\"0;url=".$site_url."404.php\">";
die;
}
...
// rest of the code
...
Q1: Is there a better way of restricting user access?
Q2: If not, is there a way of making this method more efficient / optimal?