title: Get Referer URL and FOLDER name in PHP
body: <p>I have several folders on my domain, within each folder contains an index.php file that checks to see if the database connection passes or fails, if it fails, the page is redirected to a top level file (outside of all folders) called offline.php. This part works great. The basic format I'm using to redirect if the db is offline is:</p>
  
  <pre><code>if ( !$dbconnect ) {
  header("Location: https://www.test.com/offline.php");
  }
  </code></pre>
  
  <p>Then, within the offline.php page, I need to check to see which folder brought the user to the offline.php page, and display a unique message to the user - based on the folder that brought them to the offline.php page.</p>
  
  <p>For example:</p>
  
  <p>test.com/test1/index.php redirects to offline.php, the message would say 'test1 brought you to this page'</p>
  
  <p>test.com/test2/index.php redirects to offline.php, the message would say 'test2 brought you to this page'.</p>
  
  <p>In multiple browsers I've tried the following code, which always results in 'unknown uri':</p>
  
  <pre><code>$url = 'https://' . $_SERVER['HTTP_REFERER'] ;
  if ( strpos($url,'test') !== false ) {
  echo 'test';
  } elseif ( strpos($url,'test1') !== false ) {
  echo 'test1';
  } elseif ( strpos($url,'test2') !== false ) {
  echo 'test2';
  } else {
  echo 'unknown uri';
  }
  </code></pre>
  
  <p>Suggestions?</p>
  
  <p><strong>EDIT</strong>
  Due to the unreliable nature of HTTP_REFERER I've decided to put all of the conditions within the index.php page and forget about the offline.php page. A HUGE thank you to everyone who offered suggestions!</p>