www.webdeveloper.com
Results 1 to 6 of 6

Thread: php to check which url is requested

  1. #1
    Join Date
    Oct 2011
    Posts
    54

    php to check which url is requested

    Hello,
    I want to know which url is requested,
    like test.com/bla.php or test.com/web.php so that I see bla.php and web.php

    This is what I use at the moment, but is it safe?
    PHP Code:
    <?php
    $file 
    $_SERVER["SCRIPT_NAME"];
    $break Explode('/'$file);
    $pfile $break[count($break) - 1]; 
    echo 
    $pfile;
    ?>
    Thanks in common,
    David

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,144
    Could you just use:
    PHP Code:
    $pfile basename($_SERVER['SCRIPT_NAME']); 
    ?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Oct 2011
    Posts
    54

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,144
    Quote Originally Posted by DavidBonting View Post
    Thanks, but is it safe?
    I can't think why it would not be.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Dec 2008
    Location
    Cape Town, South Africa
    Posts
    2
    You may want to use REQUEST_ADDR instead:

    PHP Code:
    $_SERVER['REQUEST_ADDR'
    That'll give you the URL, as opposed to the script being executed (the two won't always be the same).

  6. #6
    Join Date
    Oct 2011
    Posts
    54
    Thanks, but that's not what I'm looking for. The above (you) method works fine

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles