I will explain to you how to get the current URL in Codeigniter. Sometimes, we need to get the current URL path in your controller file or view file.
current_url() through we can get the current URL in your Codeigniter application. But Before to get we should load the "URL" helper to autoload.php or controller
Step 1: Load Url Helper Class in controller
$this->load->helper('url');
then call the fuction current_url in your controller file, look at the following example
application/controllers/TestCtrl
<?php
class TestCtrl extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper('url');
}
public function index(){
//this will return current page url
echo current_url();
}
}