I need to display a notification message after the header redirect page. I am using this function:
function Redirect($url) {
if(!headers_sent()) {
//If headers not sent yet... then do php redirect
header('Location: '.$url);
exit;
} else {
//If headers are sent... do javascript redirect... if javascript disabled, do html redirect.
echo '<script type="text/javascript">';
echo 'window.location.href="'.$url.'";';
echo '</script>';
echo '<noscript>';
echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
echo '</noscript>';
exit;
}
}
I am inserting an error in php SESSIONas follows:
session_start();
$_SESSION['errors'] = array();
...
array_push($_SESSION['errors'], "<span style = 'color:green;'>Success!</span>");
Redirect("somepage.php");
And to display the notification:
if(isset($_SESSION['errors']) && count($_SESSION['errors']) > 0) {
foreach($_SESSION['errors'] as $k => $v)
echo($v . "<br/>");
unset($_SESSION['errors']);
}
Send notice in SESSIONsafe and good? if not, what is the best way to display a notification after the header redirects ?!
source
share