Refresh/Redirect management to different pages in PHP. Simple function to help in refreshing and redirecting a page in PHP. This function helps in redirection by different ways. Header redirection in PHP is a efficient method. We can use meta redirection to redirect and to refresh a page in PHP.
function redirect($url,$header=false,$time=0) {
if(!headers_sent() && $header) {
header( 'refresh:'.$time.'; url='.$url.'');
exit;
}
else {
echo '<script type="text/javascript">';
echo 'window.setTimeout(function() {
window.location.href="'.$url.'";
}, '.($time*1000).');';
echo '</script>';
echo '<noscript>';
echo '<meta http-equiv="refresh" content="'.$time.';url='.$url.'" />';
echo '</noscript>';
exit;
}
}
function redirect($url,$header=false,$time=0) {
if(!headers_sent() && $header) {
header( 'refresh:'.$time.'; url='.$url.'');
exit;
}
else {
echo '<script type="text/javascript">';
echo 'window.setTimeout(function() {
window.location.href="'.$url.'";
}, '.($time*1000).');';
echo '</script>';
echo '<noscript>';
echo '<meta http-equiv="refresh" content="'.$time.';url='.$url.'" />';
echo '</noscript>';
exit;
}
}
No comments:
Post a Comment