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

Today, We want to share with you get current url in codeigniter.In this post we will show you codeigniter gets currents site url, hear for get currents controller name we will give you demo and example for implement.In this post, we will learn about PHP – How To Get Currents Url Using CodeIgniters Controller’s URL From A View with an example.

Codeigniter get current url On View Controller Model Example

Using Helper function

Make Sure the Url Helper is loaded before calling the function –

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

load “url” helper before use current_url()

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


$currentURL = current_url();
print_r($currentURL);

How to get currents url with its get request?

Load the URL helper To get currents url

echo $this->input->get('my_id');

//or

// Load the URL helper To get currents url

$currentURL = current_url(); //http://myhost/main

$params   = $_SERVER['QUERY_STRING']; //my_id=1,3

$fullURL = $currentURL . '?' . $params; 

echo $fullURL;   //http://myhost/main?my_id=1,3

For currents url

echo base_url(uri_string());

I hope you get an idea about CodeIgniter -> Get currents URL relative to base url.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment