Troy Porter
Troy Porter

Reputation: 15

Codeigniter: Redirect() refresh/location parameter

Can anyone explain the specific difference between using the 'location' and 'refresh' parameters for the redirect() function. Is it ONLY for when Windows misbehaves that you use 'refresh' or does it actually serve a more important purpose?

Upvotes: 0

Views: 4126

Answers (1)

jleft
jleft

Reputation: 3457

CodeIgniter's redirect function (located in system/helpers/url_helper.php) allows you to send HTTP headers using PHP's header() function.

The location header instructs a web browser to load a web page and is sent with a 3xx HTTP status code. For example: 301 - moved temporarily or 302 - moved permanently (CodeIgniter's default).

The Location response-header field is used to redirect the recipient to a location other than the Request-URI for completion of the request or identification of a new resource.

Refresh is actually a proprietary extension that was created by Netscape. It isn't part of the official standards, but most web browsers have adopted it and support it.


There are several reasons why you might want to use one or the other - location should be supported by all browsers that comply to the standards but refresh may not. refresh could 'break' the back button of the browser (while location won't) and may have performance issues. location sends a reason for the redirect, in a HTTP code, but refresh doesn't; it only instructs the browser to refresh a specified page.

Upvotes: 7

Related Questions