Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post

    This web page has a redirect loop | PHP redirect...

    Hey guys, any idea why Chrome is throwing this error at me?
    Code:
    This web page has a redirect loop
    The website will not load as apparently there is a looping redirect... I don't see how that could be happening :S

    PHP Code:
    <?php
    session_start
    ();
    require 
    "php/general.php";
    require 
    "pages/header.php";
    $page $_GET['page'];
    //Reload page page if no URL variable is set
    if ($page == "") { 
        
    header('Location: http://martynleeball.goodluckwith.us?page=main');
    }

    //Is the user logged in?
    if (!$_SESSION['user'] || $_SESSION['sid'] != session_id()) {
        
    //Make certain that the login page is loaded
        
    header('Location: http://martynleeball.goodluckwith.us?page=login');
        
        
    //User is not logged in, connect to database
        
    include "php/connect.php";
    }
    ?>
    <title><?php echo $titles[$page?></title>
    <link rel="stylesheet" type="text/css" href="css/main.css" />
    <script type="text/javascript">
    <?php
    include $js[$page];
    ?>
    </script>
    </head>
    <body>
    <?php
    include $pages[$page];
    ?>
    </body>
    </html>

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Start out by commenting-out the header lines, one at a time.
    If the error goes away, you'll know which one is causing the loop.

    What is happening is, you're executing a script, something tells it to go
    somewhere else, and it gets back to where it started. It continues to loop
    like that. Chrome may be the browser that detects it ... whereas the other
    browsers might just "hang up" and you'll get "browser not responding"?

    If it ends up being a header line, let us know.

    Otherwise, start commenting-out the include lines one at a time until the error disappears.

    You have to troubleshoot this on your own, because we can't run it ourselves.


    .

  • Users who have thanked mlseim for this post:

    martynball (04-11-2012)

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Assuming that the page/php code you've shown is also used for your login/general template then this will do it:
    PHP Code:
    //If no session stuff set
    if (!$_SESSION['user'] || $_SESSION['sid'] != session_id()) {
        
    //Redirect to login... and again... and again.. and again..
        
    header('Location: http://martynleeball.goodluckwith.us?page=login'); 
    Bad idea to use a header for that.

    Instead do this:
    PHP Code:
    //If no session stuff set
    if (!$_SESSION['user'] || $_SESSION['sid'] != session_id()) {
        
    //change $page to login and continue
        
    $page 'login'
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    martynball (04-11-2012)

  • #4
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post
    It seems to be the following part:

    PHP Code:
    //Is the user logged in? 
    if (!$_SESSION['user'] || $_SESSION['sid'] != session_id()) { 
        
    //Make certain that the login page is loaded 
        
    header('Location: http://martynleeball.goodluckwith.us?page=login'); 
         
        
    //User is not logged in, connect to database 
        
    include "php/connect.php"

    Edit: Oh crap yeah, tangoforce, I just noticed. I don't actually need to reload the page. I just need to redefine the variable before the rest of the page is loaded
    Last edited by martynball; 04-11-2012 at 12:45 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •