title: Trouble getting login page to redirect to secure page
body: <p>I have a login page I created using php, and I'm having an issue getting it to take me to the admin page after I've logged in correctly. I know the login I'm using is correct, since I just created it, and if it's wrong, it's supposed to tell me. However, once I login, the whole page just goes blank and the web address says I'm still on the login page instead of the admin one.</p>
  
  <p>I checked the error log and it says "PHP Warning:  Cannot modify header information - headers already sent by (output started at /admin/login.php:6) in /admin/includes/functions.php on line 4"</p>
  
  <p>This is the code the error log is referring to:</p>
  
  <pre><code>    function redirect_to($new_location) {
      header("Location: " . $new_location);
      exit;
  }
  </code></pre>
  
  <p>I don't understand what the error is pointing out. I've used this exact code before when I was learning how to create a login and admin pages, and I didn't have any problems when I tested it out then using WAMP on my computer. Now that I've put it on my website's server, this error is popping up. I'm not sure where to begin troubleshooting because if I take out that function, then it won't redirect at all. Any help would be super appreciated!!</p>
  
  <p>Here is the main code I'm using for the login page, if that helps:</p>
  
  <pre><code>&lt;?php require_once("includes/session.php"); ?&gt;
  &lt;?php require_once("includes/db_connection.php"); ?&gt;
  &lt;?php require_once("includes/functions.php"); ?&gt;
  &lt;?php require_once("includes/validation_functions.php"); ?&gt;
  
  &lt;?php
  $username = "";
  if (isset($_POST['submit'])) {
  // Process the form
  
  // validations
  $required_fields = array("username", "password");
  validate_presences($required_fields);
  
  if (empty($errors)) {
      // Attempt Login
  
      $username = $_POST["username"];
      $password = $_POST["password"];
  
      $found_admin = attempt_login($username, $password);
  
      if ($found_admin) {
              // Success
              // Mark user as logged in
              $_SESSION["admin_id"] = $found_admin["id"];
              $_SESSION["username"] = $found_admin["username"];
              redirect_to("http://thehummingbirdplace.com/admin/admin.php");
      } else {
              // Failure
              $_SESSION["message"] = "Username/password not found.";
      }
  }
  } else {
  // This is probably a GET request
  
  }   // end: if (isset($_POST['submit']))
  
  ?&gt;
  
  &lt;?php $layout_contect = "admin"; ?&gt;
  &lt;?php include("includes/layouts/header.php"); ?&gt;
  &lt;div id="main"&gt;
  &lt;div id="navigation"&gt;
      &amp;nbsp;
  &lt;/div&gt;
  &lt;div id="page"&gt;
      &lt;?php echo message();  ?&gt;
      &lt;?php echo form_errors($errors); ?&gt;
  
      &lt;h2&gt;Login&lt;/h2&gt;
      &lt;form action="login.php" method="post"&gt;
          &lt;p&gt;Username:
              &lt;input type="text" name="username" value="&lt;?php echo htmlentities($username); ?&gt;" /&gt;
          &lt;/p&gt;
          &lt;p&gt;Password:
              &lt;input type="password" name="password" value="" /&gt;
          &lt;/p&gt;
          &lt;input type="submit" name="submit" value="Submit" /&gt;
      &lt;/form&gt;
   &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;?php include("includes/layouts/footer.php"); ?&gt;
  </code></pre>