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 4 of 4
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    $_SERVER['SCRIPT_NAME'] but only the folder

    $domain = $_SERVER['HTTP_HOST'];
    $path = $_SERVER['SCRIPT_NAME'];
    $url = "http://" . $domain . $path;
    echo "$url";

    I'm trying to call the url without the current filename.
    ex: http://localhost/folder/index.php

    But I want it to just show the url without the index.php like this:
    ex: http://localhost/folder/

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You can use pathinfo($_SERVER['SCRIPT_URI']); and/or parse_url($_SERVER['SCRIPT_URI']); to dump all the file info to an array and then pick and choose the elements you want.

  • #3
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    how about something like this:

    $domain = $_SERVER['HTTP_HOST'];
    $path = $_SERVER['SCRIPT_NAME'];
    $basename = basename($_SERVER['SCRIPT_NAME']);
    $url = "http://" . $domain . $path;
    $newurl = str_replace($basename, "", $url);
    echo "$newurl";

  • #4
    New Coder
    Join Date
    May 2006
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks mlseim, it works.


  •  

    Posting Permissions

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