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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post

    domain q: www.foo.com/bar, $x='bar'; how to do this?

    If I have a URL for my website:

    http://www.foo.com/bar/

    I want to parse just the subdir 'bar' so that I get

    $x = 'bar'

    Similarly if I have http://www.foo.com/bar/poo/

    I want

    $y = 'bar/foo'

    is there a way to do this?

  • #2
    New Coder
    Join Date
    Aug 2007
    Location
    Germany
    Posts
    22
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Try using $_SERVER['REQUEST_URI'] predefined constant (or some other).

    eg if you are loading:
    http://www.mysite.com/test/index.php...t&id_theme=512

    $_SERVER['REQUEST_URI'] would be equal to "/test/index.php?id=1&test=wet&id_theme=512"

  • #3
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    That's not a proper solution.

    The server would receive the request at domain.com/bar/foo/ and look for the proper file there. Obviously it wouldn't be there.

    A few frameworks use this technique (and I've used it as well). You need to use mod_rewrite to rewrite somewhat like this: domain.com/bar/foo/ becomes: index.php?url=bar/foo/

    Then your PHP script can parse out the specifics.

  • #4
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post

    Macintosh

    Actually, I am not doing this for a mod_rewrite.

    I am doing this for a menu system.

    I have a single script on the root which serves as a menu system. I have hundreds of pages within various dirs and subdirs on my server for my website. I want to use only the one menu script for my entire site.

    The menu is set up as a parent menu "Home About Forums Contact Us Tools, etc" and a sub menu for each item from the parent menu.

    So "Tools" would have "Blogging Bookmarks RSS" as submenus.

    So, if the user is currently browsing a page under the "foo.com/tools/" menu I would have an if statement saying something like:

    Code:
    if(($_SERVER['REQUEST_URI']) = 'tools/'){
       echo '<a href="">Blogging</a>  <a href="">Bookmarks</a> <a href="">RSS</a>';
    }
    I don't want to have to make a hundred menu scripts for each and every page.

    Is this a dumb way to solve this problem? Is there a better way?

  • #5
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    aedrin has the proper solution. You will need mod_rewrite to accomplish what you're looking to do with your menu system.

  • #6
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts
    Well, you could either check the entire URL for the presence of "tools" using strpos() or else if you need the exact part of the URL as indicated in your original post you could explode the URL around "/" then return the appropriate part of the resulting array.


  •  

    Posting Permissions

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