title: php redirect loop
body: <p>I'm following a php video tutorial (it's not online sorry) from Lynda.com and used the following code, but I got the following error</p>
  
  <pre><code>Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.
  </code></pre>
  
  <p>could this be a problem with my code. i.e. the fact that the code has two <code>redirect_to</code> in the first 10 or 15 lines, or is it talking about something else?</p>
  
  <pre><code>&lt;?php require_once("../../includes/initialize.php"); ?&gt;
  
  &lt;? if(!$session-&gt;is_logged_in()){
      redirect_to("login.php"); } ?&gt;
  
  &lt;?php
  $logfile = SITE_ROOT.DS.'logs'.DS.'log.txt';
  if($_GET['clear'] == 'true') {
   file_put_contents($logfile, '');
   //add the first log entry
   log_action('Logs Cleared', "by User ID {$session-&gt;user_id}");
   //redirect to this same page so that the URL won't 
   //have "clear=true" anymore
   redirect_to('logfile.php');
  }
  ?&gt;
  
  &lt;?php include_layout_templates('admin_header.php');?&gt;
  
  &lt;a href="index.php"&gt;&amp;laquo; Back&lt;/a&gt;&lt;br/&gt;
  
  &lt;br/&gt;
  
  &lt;h2&gt;Log File&lt;/h2&gt;
  
  &lt;p&gt;&lt;a href="logfile.php?clear=true"&gt;Clear log file&lt;/a&gt;&lt;/p&gt;
  
  &lt;?php
  if (file_exists($logfile) &amp;&amp; is_readable($logfile) &amp;&amp; 
      $handle = fopen($logfile, 'r')) {//read
      echo "&lt;ul class=\"logentries\"&gt;";
      while(!feof($handle)) {
      $entry = fgets($handle);
      if(trim($entry) != "") {
      echo "&lt;li&gt;{$entry}&lt;/li&gt;";
      }
      }
      echo "&lt;/ul&gt;";
      fclose($handle);
      } else {
      echo "Could not read from {$logfile}.";
      }
  
  ?&gt;
  
  
  
  //Remember to give your form's submit tag a name="submit" attribute
  if (isset($_POST['submit'])) {//Form has been submitted.
  
  $username = trim($_POST['username']);
  $password = trim($_POST['password']);
  
  //Check database to see if username/password exist
  
  $found_user = User::authenticate($username, $password);
  
  if ($found_user) {
      $session-&gt;login($found_user);
      log_action('Login', "{$found_user-&gt;username} loggined in.");
      redirect_to("index.php");
  } else {
      //username/password combo was not found in the database
      $message = "Username/password combination incorrect.";
  } 
  } else {//Form has not been submitted.
      $username = "";
      $password = "";
      }
  ?&gt;
  &lt;?php include_layout_template('admin_header.php'); ?&gt;
          &lt;h2&gt;Staff Login&lt;/h2&gt;
          &lt;?php echo output_message($message); ?&gt;
  
          &lt;form action="login.php" method="post"&gt;
              &lt;table&gt;
                  &lt;tr&gt;
                      &lt;td&gt;Username:&lt;/td&gt;
                      &lt;td&gt;
                          &lt;input type="text" name="username" maxlength="30" value="&lt;?php
                          echo htmlentities($username); ?&gt;" /&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;Password:&lt;/td&gt;
                      &lt;td&gt;
                          &lt;input type="password" name="password" maxlength="30" value="&lt;?php
                          echo htmlentities($password); ?&gt;" /&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td colspan="2"&gt;
                          &lt;input type="submit" name="submit" value="login" /&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
          &lt;/form&gt;
          &lt;?php include_layout_template('admin_footer.php'); ?&gt;
  </code></pre>