title: php authorization to two different databases that have different privileges
body: <p>I need to authorize users to access two different databases:
  DB01 and DB02.
  Let's say that people who can access DB01 can also access DB02 but who can just access DB02 can't access DB01. 
  I've used form-guide code. This is the FORM code:</p>
  
  <pre><code>&lt;!-- Form Code Start --&gt;
  &lt;div id='fg_membersite'&gt;
  &lt;form id='login' action='&lt;?php echo $fgmembersite-&gt;GetSelfScript(); ?&gt;'      method='post' accept-charset='UTF-8'&gt;
  &lt;fieldset &gt;
  
  &lt;legend&gt;&lt;br/&gt;Login&lt;/legend&gt;
  
  &lt;input type='hidden' name='submitted' id='submitted' value='1'/&gt;
  
  
  &lt;div class='container'&gt;
      &lt;label for='username' &gt;UserName*:&lt;/label&gt;&lt;br/&gt;
      &lt;input type='text' name='username' id='username' value='&lt;?php echo $fgmembersite-&gt;SafeDisplay('username') ?&gt;' maxlength="50" /&gt;
      &lt;span id='login_username_errorloc' class='error'&gt;&lt;/span&gt;
  &lt;/div&gt;
  &lt;div class='container'&gt;
      &lt;label for='password' &gt;Password*:&lt;/label&gt;&lt;br/&gt;
      &lt;input type='password' name='password' id='password' maxlength="50" /&gt;
      &lt;span id='login_password_errorloc' class='error'&gt;&lt;/span&gt;
  &lt;/div&gt;
  
  &lt;div class='short_explanation'&gt;* required fields&lt;/div&gt;
  
  &lt;br/&gt;
  &lt;br/&gt;
  &lt;div class='container'&gt;
      &lt;input type='submit' style="font-family:'Courier'; font-size: 30px;" name='Submit' value='Submit' cursor='hand'/&gt;
  &lt;/div&gt;
  
  
  &lt;/fieldset&gt;
  &lt;/form&gt;
  &lt;!-- client-side Form Validations:
  Uses the excellent form validation script from JavaScript-coder.com--&gt;
  
  &lt;script type='text/javascript'&gt;
  // &lt;![CDATA[
  
      var frmvalidator  = new Validator("login");
      frmvalidator.EnableOnPageErrorDisplay();
      frmvalidator.EnableMsgsTogether();
  
      frmvalidator.addValidation("username","req","Please provide your username");
  
      frmvalidator.addValidation("password","req","Please provide the password");
  
  // ]]&gt;
  &lt;/script&gt;
  &lt;/div&gt;
  &lt;!--
  Form Code End (see html-form-guide.com for more info.)
  --&gt;
  </code></pre>
  
  <p>and this is the Login function inside fgmembersite.php:</p>
  
  <pre><code>    function Login()
  {
      if(empty($_POST['username']))
      {
          $this-&gt;HandleError("UserName is empty!");
          return false;
      }
  
      if(empty($_POST['password']))
      {
          $this-&gt;HandleError("Password is empty!");
          return false;
      }
  
      $username = trim($_POST['username']);
      $password = trim($_POST['password']);
  
      if(!isset($_SESSION)){ session_start(); }
      if(!$this-&gt;CheckLoginInDB($username,$password))
      {
          return false;
      }
  
      $_SESSION[$this-&gt;GetLoginSessionVar()] = $username;
  
      return true;
  }
  
  function CheckLogin()
  {
       if(!isset($_SESSION)){ session_start(); }
  
       $sessionvar = $this-&gt;GetLoginSessionVar();
  
       if(empty($_SESSION[$sessionvar]))
       {
          return false;
       }
       return true;
  }
  </code></pre>
  
  <p>I've used two different fgmembersite.php renaming everything so to be 
  fgmembersite for DB01 and fgmemebersite_db02 for DB02.</p>
  
  <p>What happened at the moment is that if I authorize a user for DB02 the user is also authorized for DB01. I guess the problem is due to the  $_SESSION.
  I didn't rename it because I think it's not possible to have S_SESSION_DB02.
  So when the user access the script and try to get access to DB01 the check on $_SESSION is already true because it was already authorized when he accessed DB02. So please can anybody help me on this to give the two different privileges but using the code available on form guide website?
  <a href="http://form.guide/php-form/php-login-form.html" rel="nofollow noreferrer">http://form.guide/php-form/php-login-form.html</a></p>
  
  <p>I </p>