Jump to content

Checking for cookie and then using header() redirect fails


Subbony

Recommended Posts

I'm using cookies to password protect my site. If a visitor can get from index.php to index2.php by using the correct password, I set a cookie. None of the other pages will show unless they have that cookie. (Yes, faulty, but it's a temporary fix until I learn how to do something better.) If they don't have the cookie, I redirect them back to index.php. So far this has been working fine.

 

Then I put this code into index.php. It's basically checking to see if the visitor has already entered the password/gotten the cookie, and if so, sends them directly to index2.php.

<?php
if (isset($_COOKIE['jbcookie'])) {
header("Location: http://www.site.com/index2.php");
exit;
}
?>

 

For some reason, though, this sends Firefox into a tailspin. "The page isn't redirecting properly. Firefox has detected that the server is redirecting the request for this address in a way that will never complete."

 

I'm using the exact same code on the other pages, except with a ! before the isset and redirection to index.php. Copy-paste! What's wrong?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.