Codeigniter Redirect

Written on 30/06/2009 – 20:45 | by webscriptz |

redirect()

Does a “header redirect” to the local URI specified. Just like other functions in this helper, this one is designed to redirect to a local URL within your site. You will not specify the full site URL, but rather simply the URI segments to the controller you want to direct to. The function will build the URL based on your config file values.

The optional second parameter allows you to choose between the “location” method (default) or the “refresh” method. Location is faster, but on Windows servers it can sometimes be a problem. 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/', 'refresh');
}

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

This was the excerpt from the codeigniter userguide but what they don’t really tell is the essential:

redirect(‘controller/function/param’, ‘refresh’);


related post

Post a Comment

About Me

Here I'll share my knowledge, discovery and experience related to my hobby and work. Most articles on this site are related to blog design, short reviews, tips and make money online. More

Find entries :