Stackable Forums: Stackable + PHP + SSL - Stackable Forums

Jump to content

Stackable + PHP + SSL Workaround for detecting when you're using SSL from PHP in Stackab

#1 User is offline   Mac Newbold Icon

  • Newbie
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 27-April 10

Posted 27 April 2010 - 06:57 PM

If you're using PHP on Stackable, and want to detect whether or not your connection is using HTTPS, there are a few things you should note:

1. Since the SSL connection terminates at the load balancer in Stackable (which must happen, so it can read the Host header and appropriately handle the request), the connection that actually arrives at your container will not actually be HTTPS.

2. That means that $_SERVER['HTTPS'] will not be set, so when you check it, it will appear as if you're not secure.

3. In most cases, that means that you'll do a redirect to the secure URL, which puts you in an infinite redirect loop.

That said, there is a pretty easy workaround that doesn't require any changes to your PHP apps. I tested this with a Magento install, and it worked like a charm. My preferred method so far is this:

1. Create a file, I called mine "stackable-ssl.php" in your doc_root folder, and put something like this in it:

<?php
$var = 'HTTP_X_STACKABLE_SSL';
if (isset($_SERVER[$var])) {
$_SERVER['HTTPS'] = $_SERVER[$var];
}
?>

2. In your .htaccess file in doc_root (create one if you don't have it already), add this line:

php_value auto_prepend_file "stackable-ssl.php"

3. Give it a test, but what you should see is that now the behavior of $_SERVER['HTTPS'] is entirely back to normal, for any PHP script you run through apache.
0



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users