redirect()

redirect($uri = '', $method = 'auto', $code = NULL)

Parameters:
  • $uri (string) – URI string
  • $method (string) – Redirect method (‘auto’, ‘location’ or ‘refresh’)
  • $code (string) – HTTP Response code (usually 302 or 303)
Return type:

void

Does a “header redirect” to the URI specified. If you specify the full site URL that link will be built, but for local links simply providing the URI segments to the controller you want to direct to will create the link. The function will build the URL based on your config file values.

The optional second parameter allows you to force a particular redirection method. The available methods are auto, location and refresh, with location being faster but less reliable on IIS servers. The default is auto, which will attempt to intelligently choose the method based on the server environment.

The optional third parameter allows you to send a specific HTTP Response Code - this could be used for example to create 301 redirects for search engine purposes. The default Response Code is 302. The third parameter is only available with location redirects, and not refresh. Examples:

if ($logged_in == FALSE)
{
        redirect('/login/form/');
}

// with 301 redirect
redirect('/article/13', 'location', 301);

Note

In order for this function to work it must be used before anything is outputted to the browser since it utilizes server headers.

Note

For very fine grained control over headers, you should use the Output Library set_header() method.

Note

To IIS users: if you hide the Server HTTP header, the auto method won’t detect IIS, in that case it is advised you explicitly use the refresh method.

Note

When the location method is used, an HTTP status code of 303 will automatically be selected when the page is currently accessed via POST and HTTP/1.1 is used.

Important

This function will terminate script execution.

doc_CodeIgniter
2016-10-15 16:32:35
Comments
Leave a Comment

Please login to continue.