Skip to main content

Posts

Showing posts from January, 2013

How to automatically redirect between HTTP and HTTPS [PHP]

Using HTTPS allows for secure and encrypted communication between your web site and the visitor's browser. Sometimes the transition doesn't happen automatically  so we need to enforce that secure communication between the server and the client, e.g. when using a shopping cart.

One way to automatically switch from HTTP to HTTPS, using php, is a quick check of the HTTP indice in the $_SERVER array. From the php manual on $_SERVER:
$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server.