Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter -> Get current URL relative to base url

Tried URI::uri_string() but can't get it to work with the base_url.

URL: http://localhost/dropbox/derrek/shopredux/ahahaha/hihihi
Returns: dropbox/derrek/shopredux/ahahaha/hihihi

but http://localhost/dropbox/derrek/shopredux/ just returns an empty string.

I want the first call to return "ahahaha/hihihi" and the second to return "". Is there such a function?

like image 208
makuumba Avatar asked Sep 07 '25 11:09

makuumba


2 Answers

// For current url
echo base_url(uri_string());
like image 169
Nessler Avatar answered Sep 09 '25 20:09

Nessler


If url helper is loaded, use

current_url();

will be better

like image 30
user3024431 Avatar answered Sep 09 '25 20:09

user3024431