Jump to content

Recommended Posts

Posted

Hi guys, looking for some help with PHP. I'd like to display the current URL that you're looking at.

 

At the moment I have:

 

 

But this echoes the /index.php at the end. Any ideas how I could get rid of the /index.php, and just display the path that we're looking at.

 

Thanks in advance :)

Tom.

Posted
i don't know of any built in way to do it, but you could explode/strip (i forget what php calls it) the variable (parse_url) then so its cuts off anything after and including the "/" and then echo it.
Posted

Unfortunately just the '$_SERVER['REQUEST_URI']' on its own still displays /index.php on the end, I just needed to hide the actual filename on the end (to make it nice and tidy!)

 

If anyone's interested, I managed to bodge it together:

 

 

$this_dir = $_SERVER['REQUEST_URI'];
if (strpos($this_dir, basename($_SERVER['REQUEST_URI'])) !== false) $this_dir = reset(explode(basename($_SERVER['REQUEST_URI']), $this_dir));
echo $this_dir;
?>

 

Now we get something like /directory1/otherthing/potato/ rather than /directory1/otherthing/potato/index.php

 

Thanks for nudging me in the right direction :)

Guest leeneilson
Posted

Glad you got it.

 

If you wanted to see what was available from the $_SERVER superglobal then you could have printed out the array by doing this

 

print_r($_SERVER);

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...