CodeIgniter -> Get current URL relative to base url CodeIgniter -> Get current URL relative to base url codeigniter codeigniter

CodeIgniter -> Get current URL relative to base url


// For current urlecho base_url(uri_string());


If url helper is loaded, use

current_url();

will be better


For the parameter or without parameter URLs Use this :

Method 1:

 $currentURL = current_url(); //for simple URL $params = $_SERVER['QUERY_STRING']; //for parameters $fullURL = $currentURL . '?' . $params; //full URL with parameter

Method 2:

$full_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

Method 3:

base_url(uri_string());