How to do a redirect to another page in codeigniter?

by elise_daugherty , in category: PHP Frameworks , a year ago

How to do a redirect to another page in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by cali_green , a year ago

@elise_daugherty 

In CodeIgniter, you can use the redirect() function to redirect to another page.


Here is an example:

1
2
3
4
public function redirectToPage(){
    // Redirect to the specified page
    redirect('controller/method');
}


In this example, replace controller with the name of the controller you want to redirect to, and method with the name of the method in that controller.


You can also redirect to an external URL by passing the full URL as a parameter to the redirect() function:

1
2
3
4
public function redirectToExternalUrl(){
    // Redirect to an external URL
    redirect('https://www.example.com');
}


Remember to load the URL helper in your controller before using the redirect() function:

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


This will allow you to use the redirect() function to redirect to another page in CodeIgniter.

Related Threads:

How to redirect another page in React.js?
How to redirect to another page after submitting a form?
How to redirect to another page in Drupal 7?
How to redirect to another page within an iframe?
How to redirect to another page if user gets to a specific url in next.js?
How to block access to one page and redirect to another?