Results 1 to 4 of 4
  1. #1
    Join Date
    May 2003

    Getting the Website File Name in URL

    Hi, I'm programming a quick system for a friend (in PHP), and I'd just like to know if there's an easy way to do the following...

    You're at the following URL:

    When you visit the URL above, I'd like the script to fetch the file name "morestuff.php" from the URL dynamically in the script. Ie: There is no string inside the script that says $url = ""; - it needs to pull it directly from the address bar (to be blunt). It would make what I'm doing so much easier if there was a simple way to do this.

    In case you're wondering why, I need a unique identifyer for each page since a code snip will be run globally on the entire site (hundreds of pages), it's kind of hard to explain, if you do understand, and have a more logical way to do that, please feel free to share it

    Thanks in advance.
    Last edited by pixd; 04-20-2004 at 07:56 PM.

  2. #2
    Join Date
    Nov 2002
    Denver, CO USA
    This should work. It will echo the current page URL and any variables passed in it.

    $URL = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 
    echo $URL;
    Last edited by mshowman; 04-20-2004 at 09:11 PM.

  3. #3
    Join Date
    Jul 2003
    $_SERVER['PHP_SELF'] <-- this always points to the currently running PHP file. It will include the path, so to just get the filename, run basename($_SERVER['PHP_SELF']);
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

  4. #4
    Join Date
    May 2003
    Perfect. Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts