Here is a quick php script that will force any http connections to https. This assumes that SSL is working properly on your server.
if ($_SERVER['SERVER_PORT']!=443)
{
$url = "https://". $_SERVER['SERVER_NAME'] . ":443".$_SERVER['REQUEST_URI'];
header("Location: $url");
}
Should also call exit, or the rest of the script will still run,and may leak information over http.
how do you force https://www. ???
One of my sites only allows for the http://www.domain.com to access ssl, so any other format ends with an error.
domain.com -> bad
http://domain.com -> bad
http://www.domain.com -> good
Nathan – thanks. I had no idea that the rest of the script would continue to run.
phpboon – I think you would just add in the www right before calling the global variable $_SERVER['SERVER_NAME']