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 2 of 2

Thread: Get base URL

  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    48
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Get base URL

    Hello,

    I want to get the actual base directory in my PHP script. Now I use the following code to get the actual location:

    Code:
    $url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    In case of http://mysite/test/index.php the result is mysite/test/index.php and in case of http://mysite/test the result is mysite/test.

    I want to get only the directory path (mysite/test) without filename in both cases.

    I have tried pathinfo(), dirname() but both removes always the last tag independent if it is a file or dir. So in case of http://mysite/test I got only mysite instead of mysite/test.

    Any idea how to solve this?

  • #2
    New Coder
    Join Date
    Jul 2005
    Posts
    81
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try to use this code
    Code:
    //return absolute path
    $dir = dirname(__FILE__);
    You could also replace absolute path with HTTP_HOST if it is necessary for your purpose with str_replace
    If you can not find a decision, maybe you have to try to change a problem

    http://www.gunman.co.nr
    http://bglinux.org


  •  

    Posting Permissions

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