Results 1 to 3 of 3

Thread: PHP: Getching foldername from URL

  1. #1
    Join Date
    Dec 2007
    Posts
    123
    Thanks
    17
    Thanked 1 Time in 1 Post

    Question PHP: Getching foldername from URL

    Hi,

    I came up with this problem last night.

    I have a URL http://www.mysite.com

    How do I fetch the folder name that was supplied in the URL.

    For example:


    http://www.mysite.com/xyz
    or
    http://mysite.com/myfolder
    or
    http://www.mysite.com/xxx


    Please note that I can either use www or http://www or just http:// in my domain name but I need to fetch the folder name that was supplied in the URL.

    PS:

    I tried the following code, but it didnt revealed the foldername supplied

    Code:
    <?php
    echo $_SERVER['HTTP_HOST'];
    ?>


    Please help.


    Thanx

  2. #2
    Join Date
    Feb 2008
    Location
    Coventry
    Posts
    103
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default

    You would have to send it through a form and then catch it on the PHP side.

    so it would be:

    Code:
    <form action="processor.php" method="get" name="example">
    <input type="textbox" name="folder_name">
    <input type="submit">
    and on the processor part it would be

    Code:
    <?
    $folder = $_GET['folder_name'];
    //do what ever with the variable $folder
    The important thing is not to stop questioning. Curiosity has its own reason for existing.

  3. #3
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Or you could use explode() to get just that part of the url.
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

Bookmarks

Posting Permissions

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