Friday, 13 July 2018

How to solve header redirection problem in php?

Header redirection in php create problems much time



I have experienced many times problem with header so I'm not using anymore header('Location: xyz.php') instead, I'm using javascript's javascript code.

some header used code like:

$query=$db_con->query("insert into tbl_contact(name,mobile)values('mak','+22823782388')");if($query){

header('location:thanks.php');

}
if (isset($_POST['contact_id'])){  

  header('Location: xyz.php');    

echo 'message';

}


You no need to using  ob_start(); and  ob_end_flush();  



ob_start();

//code

header('Location: xyz.php');

//code

ob_end_flush();

?>





some other solution :
1. Check your redirect page name

2. Use exit(); after header.

3. Clear whitespaces

4. ob_start(); 


But you should use javascript code that is definitely working

echo "";




$query=$db_con->query("insert into tbl_contact(name,mobile)values('mak','+22823782388')");

if($query){

echo "";

}