re-direct SSL pages using header statement based on port
- by bob's your brother
I found this in the header.php file of a e-commerce site.
Is this better done in a .htaccess file.
Also what would happen to any post parameters that get caught in the header statement.
// flip between secure and non-secure pages
$uri = $_SERVER['REQUEST_URI'];
// move to secure SSL pages if required
if (substr($uri,1,12) == "registration")
{
if($_SERVER['SERVER_PORT'] != 443) {
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
exit();
}
}
// otherwise us regular non-SSL pages
else
{
if($_SERVER['SERVER_PORT'] == 443) {
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
exit();
}
}