major.io words of wisdom from a systems engineer

Forcing HTTPS with PHP

To force HTTPS with a PHP script, just put this snippet near the top:

if ($_SERVER['SERVER_PORT'] != 443) {
header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
}