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
Post a Comment