I'm trying to roll out HTTPS on a small website with minimal changes, I am adding code at the top of the pages I want protected...
<?php
$securepage ="1";
if ($_SERVER['HTTPS']=='on') {
// we are on a secure page.
if (!$securepage) {
// but we shouldn't be!
$url='http://www.mywebsite.com'.$_SERVER['REQUEST_URI'];
header('location: '.$url);
exit;
}
} else {
// we aren't on a secure page.
if ($securepage) {
// but we should be!
$url='https://www.mywebsite.com'.$_SERVER['REQUEST_URI'];
header('location: '.$url);
exit;
}
}
?>
The pages I don't want protected I remove the following...
$securepage ="1";
but when I try loading the page I get an error saying the page was redirected too many times.
Anyone have any pointers as to what is wrong with the code above?
header()s are working