HTTP::redirect

HTTP::redirect – redirects the client

Synopsis

require_once 'HTTP.php';

void HTTP::redirect ( string url )

Description

This function redirects the client. This is done by issuing a Location: header and exiting.

The HTTP package is deprecated. Use HTTP2::redirect instead.

Example

Redirecting to another site

<?php
require_once 'HTTP.php';

HTTP::redirect("http://example.com/");
?>

Local redirect

<?php
require_once 'HTTP.php';

HTTP::redirect("/foo.php");
?>

This will redirect the client to /foo.php. The method will take care of adding the right hostname as required by RFC 2616.

Parameter

  • string $url - the new URL, where to client should be redirected to.

Note

This function can be called statically.

Avoid sending any kind of data to the client before calling redirect().

The location header requires an absolute URL. If not given, redirect() tries to build one from $url. So if the redirect fails, set the absolute URL manually as argument.

Negotiate language with the user's browser (Previous) HTTP2 (Next)
Last updated: Sat, 25 Oct 2014 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

There are no user contributed notes for this page.