Home » Php » php – How to redirect a page in CodeIgniter?

php – How to redirect a page in CodeIgniter?

Posted by: admin July 12, 2020 Leave a comment

Questions:

I want to redirect a page if some condition returns true. I have no idea how to do this. Can any one provide me with an example?

Or is there any way to accomplish this?

How to&Answers:

Use the redirect() function from the URL Helper.

EDIT:
load the url helper:

$this->load->helper('url');
if (condition == TRUE) {
   redirect('new_page');
}

Answer:

Use redirect() helper function.

Example :

$this->load->helper('url');

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

Answer:

Try this code after your if statement

redirect(site_url('/index'));

I hope that is helpful for you.

Answer:

$this->load->helper('url');
redirect(base_url('controller/function'));

or

redirect(base_url().'controller/function');

or

redirect('controller/function');