I try this to redirect page using PHP:
if($var="error")
echo '<script>location.href="404.php"</script>';
Works, but, is possible redirect the page directly from PHP?
I try this to redirect page using PHP:
if($var="error")
echo '<script>location.href="404.php"</script>';
Works, but, is possible redirect the page directly from PHP?
Yes, it is.
header('Location: http://google.com');
exit();
It is possible if you do it before any content:
<?php header("Location: 404.php"); ?>
If you have sent any content to the client, however, it will not work. This means even a doctype or whitespaces before the first PHP block.
Also, if you want to stop processing that page there just add exit;
or exit();
there.
Yes... you can use the location headers. Example:
<?php header('Location: 404.php'); ?>
However you can not use this if there is any kind of output before this statement.