Too many redirects

44,095

Solution 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()).

Solution 2

This is happening most likely because you are being redirected to the same logout page. I would try setting the location differently.

Solution 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 ...

Share:
44,095
AAA
Author by

AAA

Updated on July 16, 2020

Comments

  • AAA
    AAA almost 4 years

    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.