问题
I can't find the solution to this one. Basically we are using a vanity url system so its user.domain.com. All files are accessed like user.domain.com/home.php etc. When you clear cookies the redirects work, it prompts them to login again. But when i use logout, it still works but when they go back to the link to login, (user.domain.com, has a login form on the landing page for the user) it won't work. The error i get is
Error Message:
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.
This problem can sometimes be caused by disabling or refusing to accept
cookies.
Redirect Code for all member pages:
if(!isset($_SESSION['user_name'])) { header("Location: http://$_SERVER[HTTP_HOST]");}
Note: The $_SERVER[HTTP_HOST] captures the user.domain.com value for redirect.
Logout code:
<?php
session_start();
session_destroy();
header( 'Location: $_SERVER[HTTP_HOST]' ) ;
?>
The only way for this issue to go away is if users clear their cookies.
UPDATE: After using the logout.php i went to one of the member pages user.domain.com/home.php instead of it redirecting to user.domain.com for login it gave me the redirect error. Could this be an issue with the sessions or something with the headers?
What can i enhance or add to fix this? I have tried Googling but haven't found anything particular to this. I really need some help in fixing this. Thanks.
This is the error message i get in Safari:
Too many redirects occurred trying to open “http://user.domain.com/home.php”.
This might occur if you open a page that is redirected to open another page which then is redirected to open the original page.
回答1:
The browser is stopping you from hammering the server with a bunch of requests. This is most likely due to the header()
sending you to a page which in turn sends you to the same page (or page with the same header()
).
回答2:
This is happening most likely because you are being redirected to the same logout page. I would try setting the location differently.
回答3:
Happened to me when i was redirecting back to the same page with the same parameters which would cause in infinite loop of requests to the same page by the browser if the browser would not stop on the second iteration and give this error.
Best bet - debug your code and see if you are reentering the page with the same query strings/post params ...
回答4:
The problem could lie in the page that you are forwarding to rather than the page you are forwarding from This happened to me when the page I was forwarding to (home.php) from a page forwardingPage.php failed an authentication check.
Format on the receiving home.php page was
if authentication check passes...do this else if authentication check fails use header function to forward back to the same forwardingPage.php
The authentication check was failing every time so the page got forwarded and then back to itself. I fixed the authentication check and problem solved
来源:https://stackoverflow.com/questions/4831152/too-many-redirects