Jump to content


Photo

Using the REQUEST_URI statement...


  • Please log in to reply
3 replies to this topic

#1 mkosmosports

mkosmosports
  • Members
  • PipPipPip
  • Advanced Member
  • 196 posts

Posted 24 October 2006 - 01:50 PM

I have the following variable defintition : $currentt = $_SERVER['REQUEST_URI'];
echoing this gives me the current URL that is being used. However, I would like to get it to only show the name of the html page that is being used.

For example, currently if the url is "http://localhost/ind...ex.htm?g=2&h=4", and I echo $currentt I want it only to return "index.htm" not the entire url...

Does anyone know of a way that this can be done?

Thanks.
mkosmosports

#2 mkosmosports

mkosmosports
  • Members
  • PipPipPip
  • Advanced Member
  • 196 posts

Posted 24 October 2006 - 02:24 PM

Nevermind, the below script is working for me... :D

  $full_path = getenv("REQUEST_URI"); //retrieves the full url
  $pagename = basename($full_path); //retrieves the name of the html page youre using (with or without any url parameters)....

  $currentt = substr($pagename //makes sure only the html page name getx extracted...
  , strrpos($pagename, "/")
  , strpos($pagename, ".html"));

The above variable $currentt will extract the name of the current html page thats being used and nothing but....

#3 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 24 October 2006 - 02:25 PM

alternatively..

<?php

echo $_SERVER['SCRIPT_NAME'];

?>


#4 mkosmosports

mkosmosports
  • Members
  • PipPipPip
  • Advanced Member
  • 196 posts

Posted 24 October 2006 - 03:31 PM

I knew there was something simpler around..... :P Thanks Jenk. I will use your alternative solution.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users