What are differences between location and refresh in codeginiter redirect function? What are differences between location and refresh in codeginiter redirect function? codeigniter codeigniter

What are differences between location and refresh in codeginiter redirect function?


It does not have to do only with Codeigniter. These are the 2 methods that you can use to reload (or redirect) a page.

With Location: header you are sending a 3xx status code (usually 301 or 302) to the client's browser which usually indicates that the content has temporarily moved. Using the appropriate code will give more information to the client about the reason you are doing the redirection. This will be useful especially for search engines.

Also the browser does not have to download all the page's content before doing the redirect but it does it immediately as it gets the status code from the server and it goes to the new page instead. This way you do not break the 'back' button of the browser.

With Refresh meta tag or HTTP header you send a request to the client's browser to refresh the page without indicating any information about the reason you are doing it or the original and new content. Browser has to first download all the page content and then after the time (in seconds) specified in the Refresh it will redirect to the other page (usually 0 seconds).

Also if a user hits the 'back' button of his browser it will not work as it should since it will take him to the previous page and it will use Refresh again and send him to the next from where he pressed the button.

Above statements are according to W3C article here


Codeigniter redirect method:

/** * Header Redirect * * Header redirect in two flavors * For very fine grained control over headers, you could use the Output * Library's set_header() function. * * @access  public * @param   string  the URL * @param   string  the method: location or redirect * @return  string */if ( ! function_exists('redirect')){    function redirect($uri = '', $method = 'location', $http_response_code = 302)    {        if ( ! preg_match('#^https?://#i', $uri))        {            $uri = site_url($uri);        }        switch($method)        {            case 'refresh'  : header("Refresh:0;url=".$uri);                break;            default         : header("Location: ".$uri, TRUE, $http_response_code);                break;        }        exit;    }}

PHP header

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