title: Detecting HTTPS vs HTTP on server sending back nothing useful
body: <p>So kind of very similar to "<a href="https://stackoverflow.com/questions/452375/detecting-https-requests-in-php" title="Detecting https requests in php">Detecting https requests in php</a>":</p>
  
  <p>Want to have <a href="https://example.com/pog.php" rel="nofollow noreferrer">https://example.com/pog.php</a> go to <a href="http://example.com/pog.php" rel="nofollow noreferrer">http://example.com/pog.php</a> or even vice versa.</p>
  
  <p>Problems:</p>
  
  <ul>
  <li>Can't read anything from $_SERVER["HTTPS"] since it's not there</li>
  <li>Server is sending both requests over port 80, so can't check for 443 on the HTTPS version</li>
  <li><code>apache_request_headers()</code> and <code>apache_response_headers()</code> are sending back the same thing</li>
  <li>Can't tell the loadbalancer anything or have it send extra somethings</li>
  <li>Server feedback data spat out by the page on both URL calls is exactly the same save for the session ID. Bummer.</li>
  </ul>
  
  <p>Are there any on page ways to detect if it's being called via SSL or non-SSL?</p>
  
  <p><strong>Edit</strong>: <code>$_SERVER["HTTPS"]</code> isn't there, switched on or not, no matter if you're looking at the site via SSL or non-SSL. For some reason the hosting has chosen to serve all the HTTPS requests encrypted, but down port 80. And thusly, the <code>$_SERVER["HTTPS"]</code> is never on, not there, just no helpful feedback on that server point. So that parameter is always be empty. </p>
  
  <p>(And yeah, that means it gets flagged in say FF or Chrome for a partially invalid SSL certificate. But that part doesn't matter.)</p>
  
  <p>Also, the most that can be gotten from detecting the URL is up to the point of the slashes. The PHP can't see if the request has <code>https</code> or <code>http</code> at the front. </p>