-1

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?

ivanaugustobd
  • 466
  • 5
  • 11

5 Answers5

0

Yes, it is.

header('Location: http://google.com');
exit();
Wiggler Jtag
  • 659
  • 7
  • 23
  • +1 for [exit after header](http://stackoverflow.com/questions/2747791/why-i-have-to-call-exit-after-redirection-through-headerlocation-in-php) – Dave Chen Nov 02 '13 at 19:46
-1

PHP redirects are done with header()

header('Location : '404.php');

DOCS

charlietfl
  • 169,044
  • 13
  • 113
  • 146
-1

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.

PurkkaKoodari
  • 6,493
  • 5
  • 36
  • 54
-1

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.

SpiderLinked
  • 333
  • 1
  • 6
  • 14
-1

Use header() function

header("Location: 404.php");
exit();
Sumit Bijvani
  • 8,012
  • 17
  • 49
  • 82