How to get current url in controller or view in Codeigniter?

Today now in this post i will show you How to get current url in controller or view in Codeigniter?Sometimes, we may need to get the current URL path in our controller file or any view file. So, we can get simply by using “url” helper. Codeigniter is provide us url helper library on that way we can get the existing page url or base url etc.

By using current_url() through we can get the current url in our Codeigniter application. But, we should load the “url” helper before use the current_url(). we can load the url helper as like as bellow:

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

Now in the bellow example, we can see code how we can get the current url in our controller file.

So, let’s see.

this->load->helper('url');
$currentURL = current_url();
print_r($currentURL);

Read Also : Laravel 8 Mobile Number Verification Tutorial

Thanks for read. I hope it help you. For more you can follow us on facebook.

Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.