PHP Test URL for SSL under a Load Balancer

Most likely your application will be under a load balancer when in production. If you need to test if the url is HTTPS with PHP you will probably use env(‘HTTPS’), but under a load balancer that wont work.

You will need to check for HTTP_X_FORWARDED_PROTO server variable.

Off course testing this under your local environment can be painful, but here is a small tip that works wonders. Change your http-ssl.conf and on your virtual host add:

RequestHeader set X-Forwarded-Proto "https"

This will automatically add the HTTP_X_FORWARDED_PROTO on the response header from Apache to your app.

The same logic can be used for other Apache header responses.

About these ads

About mcloide

Making things simpler, just check: http://www.mcloide.com View all posts by mcloide

One Response to “PHP Test URL for SSL under a Load Balancer”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 182 other followers

%d bloggers like this: