Pages

Redirect page

The header() function sends a raw HTTP header to a client but it is important to notice that header() must be called before any actual output is sent. In my experience, Sometime we have to redirect the page after actual output is sent . In that case , I use this fucntion .

function get_redirect($location) {
 print "<script>";
 print " self.location='$location'"; 
 print "</script>";

}

Use


get_redirect('index.php');
I found this function in php.net which seems very useful
<?php
function redirect($filename) {
    if (!headers_sent())
        header('Location: '.$filename);
    else {
        echo '<script type="text/javascript">';
        echo 'window.location.href="'.$filename.'";';
        echo '</script>';
        echo '<noscript>';
        echo '<meta http-equiv="refresh" content="0;url='.$filename.'" />';
        echo '</noscript>';
    }
}
?>

Use


redirect('http://www.google.com');