Pick up page name in PHP?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RogerInHawaii
    New Member
    • Jun 2007
    • 13

    Pick up page name in PHP?

    Is there a way, within a PHP script, to pick up the name of the web page that the script is being run on?
  • bonski
    New Member
    • Jun 2007
    • 53

    #2
    Originally posted by RogerInHawaii
    Is there a way, within a PHP script, to pick up the name of the web page that the script is being run on?

    ei roger...

    [PHP]$scriptname=get env("SCRIPT_NAM E");
    echo $scriptname;[/PHP]


    bonski ^___^

    Comment

    • RogerInHawaii
      New Member
      • Jun 2007
      • 13

      #3
      bonski,

      Thanks for the reply.

      That looks like it will return the name of the script file in which the PHP code resides. What I'm looking for is to get access to the name of the web page from within which that script is included.

      That is, let's say I have a page named "MyPage.php " and within that page I do an include "MyPHPFunctions .php". WHat I want to access, from within MyPHPFunctions. php, the name of MyPage.php. Kind of like getting the "parent" of the current include file.

      - Roger

      Comment

      • bonski
        New Member
        • Jun 2007
        • 53

        #4
        Originally posted by RogerInHawaii
        bonski,

        Thanks for the reply.

        That looks like it will return the name of the script file in which the PHP code resides. What I'm looking for is to get access to the name of the web page from within which that script is included.

        That is, let's say I have a page named "MyPage.php " and within that page I do an include "MyPHPFunctions .php". WHat I want to access, from within MyPHPFunctions. php, the name of MyPage.php. Kind of like getting the "parent" of the current include file.

        - Roger
        ok.... roger.. you can still put this script inside the "MyPHPFunctions .php"

        [PHP]$scriptname=get env("SCRIPT_NAM E");
        $viewpage = basename($scrip tname);
        echo $viewpage.'<br> ';[/PHP]

        just give a try... bonski

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          If I'm understanding you correctly, this should also work.
          [code=php]
          //Note. this will return the entire URL
          // including any GET data.
          $pageURL = $_SERVER['PHP_SELF'];
          [/code]

          Included files are essentially inlined into the file that calls the include command, so if you include 'myFunctions.ph p' into 'myPage.php' the code from 'myFunctions.ph p' is being executed as a part of 'myPage.php'.

          Comment

          Working...