So I'm building a website where the user registers and when logged in, he/she is able to do somethings such as unflagging quotations (adding back) that where flagged (removed from the public view) by users not registered. However, I'm having problems figuring out why my header('location: index.php') on my controller file won't redirect the page to the index.php page.I already tried to comment out all instances of echo("something") in my controller to see if that's why it's not working, but it didn't work either. I have no clues left of why header('location: index.php') is not working. 

Here is my controller file where I redirect the user after successful registration:

```
<?php 

session_start();
include "DataBaseAdaptor.php";

function GetQuotes($theDBA) {
    $array = $theDBA->getQuotesAsArray();
    $quotes = [];
    //$quotes[] = [];

    $i = 0;
    $j = 0;
    $id = "";
    if(count($array)>0){
    foreach($array as $item) {
        $quotes[$i][$j] = $item['quote'];
        $quotes[$i][$j+1] = $item['author'];
        $quotes[$i][$j+2] = $item['rating'];
        $quotes[$i][$j+3] = $item['id'];
        $i++; 
    }}
    return $quotes;
}
$quotes = GetQuotes($theDBA);                         //This to display the quotes initially

// This part is for registering the user
if(isset($_GET['user']) && isset($_GET['pass'])) {
    $username = $_GET['user'];
    $password = $_GET['pass'];
    $hashed_password = password_hash($password, PASSWORD_DEFAULT);  

    // If false, then username already exists
    if (!$theDBA->register($username,  $hashed_password )) {
       //echo("Username already exists");  
    }
    else {          //The control does come to this block and the else is evaluated to true. However it won't redirect
        $_SESSION['user'] = $username;
        header('Location: index.php');

    }
}
// Register ends here----------------------------------------------------------------------------------

//This part is for adding quote
if(isset($_GET['quote']) && isset($_GET['author'])) {
    $quote = $_GET['quote'];
    $quote = str_replace("'", "", $quote);

    $author = $_GET['author'];
    $theDBA->addQuote($quote, $author);
    $quotes = GetQuotes($theDBA);
    header( 'Location: index.php' );
}

// This is for logging in
$quotes = GetQuotes($theDBA);
$user = "";
$pass = "";
if(isset($_GET['p']) && isset($_GET['q'])) {
     $user = isset($_GET['p']);
     $pass = isset($_GET['q']);

}
for ($i = 0; $i < count($quotes); $i++){
    if($user === $quotes[$i][0]) {
        $_SESSION['user'] = 'Rick';
        header('Location: index.php');
    }
}

echo json_encode($quotes);
?>

```

I don't know if you need my model.php (DataBaseAdaptor.php in my case), but here is. Everything related to the database, like all sql operations are working. but in case you need it, find it bellow. Feel free to send edit suggestions to my post if you find model.php not to be necessary( but please, do it only if you are sure it's not necessary). Thanks!

Here is model.php

```
<?php

//
// Author: Rick Mercer.   File name: model.php
//

class DatabaseAdaptor {
// The instance variable used in every one of the functions in class 
DatbaseAdaptor
private $DB;

// Make a connection to an existing data based named 'first' that has table 
customer
public function __construct() {
$db = 'mysql:dbname=quotes; charset=utf8; host=127.0.0.1';
$user = 'root';
$password = ''; 

try {
  $this->DB = new PDO ( $db, $user, $password );
  $this->DB->setAttribute ( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
} catch ( PDOException $e ) {
echo ('Error establishing Connection');
  exit ();
}
}

// Return all records as an associative array.
public function getQuotesAsArray() {
$query = "SELECT * FROM quotations WHERE flagged = 0 ORDER BY rating DESC";

$stmt = $this->DB->prepare($query);
$stmt->execute ();
// fetchall returns all records in the set as an array
return $stmt->fetchAll ( PDO::FETCH_ASSOC );
}

   // Checks if a user exists, if not register the new user
  public function register($username, $password) {
  $query = "SELECT * from users";
  $stmt = $this->DB->prepare($query);
  $stmt->execute ();

// fetchall returns all records in the set as an array
$array = $stmt->fetchAll ( PDO::FETCH_ASSOC );

// If there are no registered users, just register the new user
if(count($array) == 0) {
    $query = "INSERT INTO users (username, hash) VALUES ('$username', 
'$password')";
    $stmt = $this->DB->prepare($query);
    $stmt->execute ();
    return true;
 // header( 'Location: index.php' );
}

foreach($array as $item) {
    if($username == $item['username']) {
        return false;
    }
}
    $query = "INSERT INTO users (username, hash) VALUES ('$username', '$password')";
    $stmt = $this->DB->prepare($query);
    $stmt->execute ();
    return true;
   //header( 'Location: index.php' );
 }

 public function addQuote($quote, $author) {
 $query = "INSERT INTO quotations (added, quote, author, rating, flagged) 
 VALUES(now(), '$quote', '$author', 0, 0)";
 $stmt = $this->DB->prepare($query);
 $stmt->execute ();
 }

 } // End class DatabaseAdaptor

$theDBA = new DatabaseAdaptor();
?>

Any help is appreciated. Thanks!

```