How do I get the current files file name?

Discussion in 'PHP' started by Imozeb, Mar 25, 2010.

  1. #1
    I have a PHP page and I want to get the file name of the page through PHP. How can I do this?

    Thanks.

    ~imozeb :)
     
    Imozeb, Mar 25, 2010 IP
  2. wissam

    wissam Well-Known Member

    Messages:
    2,289
    Likes Received:
    78
    Best Answers:
    1
    Trophy Points:
    185
    #2
    that whould be
    
    <?php
    function curPageURL() {
     $pageURL = 'http';
     if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
     $pageURL .= "://";
     if ($_SERVER["SERVER_PORT"] != "80") {
      $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
     } else {
      $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
     }
     return $pageURL;
    }
    ?>
    
    <?php
      echo curPageURL();
    ?>
    
    
    Code (markup):
     
    wissam, Mar 25, 2010 IP
  3. mnvlxxx

    mnvlxxx Peon

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I don't know if i misunderstood you question, but i think you could just use $_SERVER['PHP_SELF']
     
    mnvlxxx, Mar 25, 2010 IP
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    <?php
    echo basename(__FILE__);
    ?>
    PHP:
    or

    <?php
    echo basename($_SERVER['SCRIPT_FILENAME']);
    ?>
    PHP:
    or

    <?php
    
    echo basename($_SERVER['PHP_SELF']);
    
    ?>
    PHP:
     
    danx10, Mar 25, 2010 IP