-3

Getting a headers redirect error on line 20 and don't know why....

My code is as follows.

   <?php
    require_once("functions.php");
    $username = trim($_POST['username']);
    $password = trim($_POST['password']);
       if ($username&&$password){
    session_start();
     require_once("Connection.php");
      mysqli_select_db($db_server, $db_database) or 
                                                  die("Couldn't find db");
       $username = clean_string($db_server, $username);
       $password = clean_string($db_server, $password);  
       $query = "SELECT * FROM UserDatabase WHERE username='$username'";
        $result = mysqli_query($db_server, $query);
        if($row = mysqli_fetch_array($result)){
        $db_username = $row['username'];
        $db_password = $row['password'];
         if($username==$db_username&&($password)==$db_password){
              $_SESSION['username']=$username;
              $_SESSION['logged']="logged";
              header('Location:Log_homepage.php');

The functions page contains the following:

 <?php
 function clean_string($db_server = null, $string){ 
   $string = trim($string);  
   $string = utf8_decode($string); 
   $string = str_replace("#", "#", $string);  
   $string = str_replace("%", "%", $string);  
      if (mysqli_real_escape_string($db_server, $string)) {
        $string = mysqli_real_escape_string($db_server, $string); 
}
 if (get_magic_quotes_gpc()) {
 $string = stripslashes($string);
 }
  return htmlentities($string);
 }

         ?>

The connection page contains the following:

   <?php
  $db_hostname = 'localhost';
  $db_username = '_____'; 
  $db_password = '_______'; 
  $db_database = '_______';
  $db_server = mysqli_connect($db_hostname, $db_username,
                                         $db_password);
  if (!$db_server){
  die("MySQL connect failed: " . mysqli_connect_error());
  }else{
 mysqli_select_db($db_server, $db_database) or
   die ("Couldn't find database");
   }
    ?>

I need the the header to redirect to that page in that exact place.

Thanks!

1 Answers1

0

Your include files are full of extra spaces. Remove them and try again.

You have space before the open php tag and before and after the close php tag.

effulge
  • 77
  • 6
  • If you read the comments, no, they don't. As seen [here](http://stackoverflow.com/questions/21103753/getting-a-headers-redirect-error-and-dont-know-why#comment31749672_21103753). – Daedalus Jan 14 '14 at 00:13
  • Do you have an editor that shows hidden characters? It may be a BOM that you are missing? – effulge Jan 14 '14 at 00:14
  • Run it without the Header redirect and turn errors on. Does it show anything? How many lines does it show when you view source? – effulge Jan 14 '14 at 00:20
  • One more thing you can try, make a new document and put all the code into that one. Check to see if it works. This would eliminate the spaces/BOM from other include files. – effulge Jan 14 '14 at 00:27