title: Restricting access to php scripts for limited access users
body: <p>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.</p>
  
  <p>I am doing this in the following manner:</p>
  
  <pre><code>// $_SESSION['systemid'] is set with a value of say, '1'
  $permissionArray = $objACCESS-&gt;getPermissions($_SESSION['systemid']);
  
  // getPermissions returns an array like the following (for that systemid):
  // 0 =&gt; {'systemid' =&gt; '1', 'permission_type' =&gt; 'createcontent' }
  // 1 =&gt; {'systemid' =&gt; '1', 'permission_type' =&gt; '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 "&lt;meta http-equiv=\"refresh\" content=\"0;url=".$site_url."404.php\"&gt;";
      die;
  }
  
  ...
  // rest of the code
  ...
  </code></pre>
  
  <p>Q1: Is there a better way of restricting user access?</p>
  
  <p>Q2: If not, is there a way of making this method more efficient / optimal?</p>