php - Header function not redirecting? -


please have php code(below) creates , inserts user database after validating user inputs. storing users input in array. problem creates user , inserts database not redirect. here's code

$validation = new validate();  if($validation->passed()) {  //if success, insert(create) user  try {   $user = new user();   $salt = crypt::salt(32);    $user->insert(array(     'username' => accept::get('username'),     'password' => crypt::make(accept::get('password'), $salt),     'salt'  => $salt,     'name' =>  accept::get('name')     ));   //after creation, redirect user  header('location : index.php');  exit();   } catch(exception $e) { //otherwise display errors      die("error : can not register user ".$e->getmessage());  } 

this code creates user in database, not redirect. don't understand why.

1) make sure not echo/output before header() function not blank space

2) write these @ top of page see errors

<?php error_reporting(e_all); ini_set('display_errors', '1'); 

3) try ob_start(); or ob_flush();

ob_start();// @ top of page     $validation = new validate();      if($validation->passed()) {      //if success, insert(create) user      try {       $user = new user();       $salt = crypt::salt(32);        $user->insert(array(         'username' => accept::get('username'),         'password' => crypt::make(accept::get('password'), $salt),         'salt'  => $salt,         'name' =>  accept::get('name')         ));       //after creation, redirect user      header('location : index.php');      exit();     ob_flush();       } catch(exception $e) { //otherwise display errors          die("error : can not register user ".$e->getmessage());      } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -