tapaljor tapaljor - 1 month ago 5
PHP Question

PHP: Force redirect page

I have page which is calling through JQuery ajax. I do update in page experience.php. Hence, update part is working fine.

<?php
if( isset($_POST["update"]) ) {

$status = false;
$status = $experience->update($_POST);

if($status) {
$idh = md5($_SESSION["mainid"].$_SESSION["tsa_gong"]);
header("Location: particular_one.php?idh=$idh&ajax_show=experience");
} else {
echo '<p style="color: #fff;">Error: cannot update</p>';
}
}


But PHP header function is not working fine. It has following error. And it hangs in there which looks ugly for user.


[WARNING] Warning: Cannot modify header information - headers already sent by..


I want to ignore warning or error I get. I want PHP to forcefully redirect to page I intended. Is there any ways to achieve that?

Answer

you can use inline JavaScript

header("Location: particular_one.php?idh=$idh&ajax_show=experience");

echo "<script type='text/javascript'>window.location.href = 'particular_one.php?idh={$idh}&ajax_show=experience';</script>";
Comments