Jaydeepsinh Jadeja
Jaydeepsinh Jadeja

Reputation: 391

How to redirect a page in CodeIgniter?

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?

Upvotes: 8

Views: 65444

Answers (4)

Logan
Logan

Reputation: 1694

Use redirect() helper function.

Example :

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

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

Upvotes: 6

Arun Yokesh
Arun Yokesh

Reputation: 1354

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

or

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

or

redirect('controller/function');

Upvotes: 1

Yan Berk
Yan Berk

Reputation: 14428

Use the redirect() function from the URL Helper.

EDIT: load the url helper:

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

Upvotes: 22

Jone
Jone

Reputation: 27

Try this code after your if statement

redirect(site_url('/index'));

I hope that is helpful for you.

Upvotes: 2

Related Questions