page redirect in codeigniter code example

Example 1: redirect in codeigniter

//You can use redirect in codeigniter by loading helper 'url'
$this->load->helper('url');

//The redirects functions accepts two parameters to execute the function first is 'Location Url' and second parameter allows the developer to use different HTTP commands to perform the redirect "location" or "refresh".
if (!$user_logged_in)
{
  redirect('/account/login', 'refresh');
}

Example 2: codeigniter redirect

$this->load->helper('url');
redirect('/account/login', 'refresh');

Example 3: codeigniter 4 redirect to home

return redirect()->to(site_url());

Tags:

Php Example