I’ve done tons of redirects using PHP’s header function. This one has stumped me.
On my dashboard controller, I check whether or not the $_SESSION[‘loggedin’] is set. If it’s not set, I want to send the user back to the main page. However, I keep getting the “too many redirects” error, even though I only have it set once. Can anyone help me out? Thanks for the help in advance!
Here’s my code –
function index() {
if(!isset($_SESSION['loggedin'])) {
header("Location: ./");
} else {
die("The user is logged in.");
}
}
./means “here”, so yes, you’re redirecting in a circle. You probably mean/, the root.The Location header field should really contain a complete, absolute URL though. So you should redirect to
http://example.com/. Relative URLs just happen to be (incorrectly) accepted by some browsers.