5

I have a site that runs on php and I have to redirect the user when the user logs in, comments, or posts. I am trying to cut down on time with redirects as much as possible, and to redirect a user to another page, I currently use:

 echo "<script>location.href='www.redirect.url'</script>";

I am new to using PHP to redirect users and this is the fastest way that I know, is there a faster way? And if so, what is it?

DMVerfurth
  • 172
  • 1
  • 13

1 Answers1

7

The fastest option is issuing a raw HTTP header:

header("Location: http://www.redirect.url");
exit;

The exit is to make sure nothing below gets executed when we redirect.

important note: there can be no output sent before the call.

less important, you should if you can use the full URI

ref: http://php.net/manual/en/function.header.php