Redirect user to another page using HTTP headers or javascript
Here are two ways to redirect the user to another page.
First you can send headers with the location of the new page. Note that this only works if you haven't sent anything to the browser.
<?php
function HTML_RedirectTo($page) {
// If you are using sessions and want to pass the session_id use this
//header("Location: http://{$page}?PHPSESSID=" . session_id());
header("Location: http://{$page}");
die();
}
?>
If for some reason you had to output something and the above method is not an option, you can use javascript:
<?php
function HTML_JSRedirectTo($page) {
?>
<script language="javascript">
window.location ='< ?php echo $page; ?>';
</script>
<?php
die();
}
?>
Leave a comment