Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Function / Constant returning path of current file...

    Say the current page is:

    http://mysite.com/somedir/go.php

    Is there a constant or function that will return a string / contain the path to the file? (in this case "http://mysite.com/somedir/")

    Failing that, how can I get to this result?
    skinme.net / v2.php (design nearly completed)

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,073
    Thanks
    11
    Thanked 98 Times in 96 Posts
    This will print out all the variables that PHP has available run it and you will see your options...

    PHP Code:
    <?
    ob_start
    ();
    print_r($GLOBALS);
    $str ob_get_contents();
    $str=nl2br($str);
    ob_end_clean();echo $str;
    ?>
    but I think
    echo 'http://'.$HTTP_SERVER_VARS[HTTP_HOST].$HTTP_SERVER_VARS[REQUEST_URI];

    will be what you are looking for?

    (note 4.02+ & you can do this)
    echo 'http://'.$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI];
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New Coder
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That was the beginning of what I needed. I then got rid of the file name:

    PHP Code:
    <?php
    $fullpath 
    'http://'.$HTTP_SERVER_VARS[HTTP_HOST].$HTTP_SERVER_VARS[REQUEST_URI];
    $thisfile basename($fullpath);
    $cutoffpos strpos($fullpath,$thisfile);
    $thisdir substr($fullpath0$cutoffpos);
    ?>
    Say the current file is: http://mysite.com/somedir/go.php
    $thisdir will contain http://mysite.com/somedir/.

    Thanks.
    skinme.net / v2.php (design nearly completed)


  •  

    Posting Permissions

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