I'm trying to prevent certain pages on my site from being accessed through HTTPS, and (for whatever reason) I want to do it through PHP and not through a .htaccess.
Here's the code I'm using:
if ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ) {
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://mydomain.com");
}
But for some odd reason, I'm stuck in an infinite loop, and can't get it to work. When I check the response headers in firebug, I see that the location header is set to https://mydomain.com instead of http://mydomain.com, which is causing the infinite loop.
EDIT: Accessing http://mydomain.com directly does work.
Also note: this works if I send'em to a different page, but not if I send them to the same page. So if I run the above code in mydomain.com/somePage.php, and then try accessing it through https://mydomain.com/somePage.php, it'll properly redirect to (non-SSL-ed) homepage. Only when I redirect them to the same page with a different protocol does it ignore the protocol.
What am I doing wrong?
header("Location: http://and notheader("Location: https://... or is that what the code actually says?issetor wouldif (!empty($_SERVER['HTTPS']))suffice? I'm not sure you need to double on theissetand== 'on'. If it's not https, the $_SERVER['HTTPS'] var will be empty, so just checking that single variable for a value should work - at least that's what I would have assumed. I don't have a server with HTTPS enable to test with right now.301header?