title: Apache2 Reverse Proxy with PHP Login Page (Check for session var before forwarding to server)
body: <p>I have an apache2 reverse proxy setup fine for an ssl backend server.</p>
  
  <p>(WWW -->  Apache2  --> Server)
  Works fine.</p>
  
  <p>I have a nice method of doing 2FA using TOTP and looking to get this working for this particular web application.</p>
  
  <p>How can I get apache2 to check for a sessionid / var (check if a user is authenticated using my php script) before forwarding them on to the server behind the proxy?</p>
  
  <p>IE: Im looking for this..</p>
  
  <ol>
  <li>User connects to proxy and is presented with a login form.</li>
  <li>User gets authenticated a session ($_SESSION['loggedin'] = "1")</li>
  <li>Apache checks if that = 1, if so, forward to proxied host. If not, present login.php (as an example)</li>
  </ol>
  
  <p>Essentially what i am trying to achieve is a 2factor mech as the app being proxied allowed one type and my php script using totp does another.</p>
  
  <p>I just need apache top be able to check if they are logged in in php before forwarding to the proxied host.</p>
  
  <p>Reverse proxy works fine currently, just need this extra "login" before being proxied to work..</p>
  
  <p>Current config is essentially this..</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
  ProxyPreserveHost On
  
  ProxyPass / http://10.0.0.1:80/
  ProxyPassReverse / http://10.0.0.1:80/
  </code></pre>
  
  <p></p>
  
  <p>Would be nice to have something in the virtualhost to say something like, IF USER SESSION VAR X = Y then Proxy.</p>
  
  <p>Any ideas?</p>
  
  <p>I cant find anything whatsoever online.</p>