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");
}
Related posts:
- php/linux – performing an http post the easy way
- setting up ssl for apache2 on debian linux
Tags: header, redirect
This entry was posted
on Monday, May 14th, 2007 at 3:26 am and is filed under Programming.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
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']