Get Current Page URL in Codeigniter

September 26, 2020

Codeigniter provides a simple function to get the current page URL in a Codeigniter project easily. By using this function we can get the path to the current page to a variable or we can print the URL.

How to get the Current Page URL in Codeigniter?

To get the current page URL you need to load the URL helper class in your Codeigniter project first.

Step 1: Loading URL Helper Class

Loading URL helper class using the autoload:

Using the below code piece you can load the URL helper class automatically in every Controller.

$autoload['helper'] = array('url');

Or Loading URL helper class in controller class:

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

Step 2: Get the current page URL

$current_page_url = current_url();
echo $current_page_url;

Tagged in:
About Author
Adeeb C (227 Articles)

Adeeb C is a Web Designer, Web Application Developer, Android App Developer, WordPress Developer, Professional Blogger. He has 5 years of experience in WordPress, Web Developing, Professional Blogging, and 2 years of experience in Android App Developing.