Results 1 to 5 of 5

Thread: Need help building a variable path

  1. #1
    Join Date
    Jul 2005
    Posts
    101
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Need help building a variable path

    I want to use the same PHP include file for my navbar on all pages. The navbar will be displayed at different levels of the directory structure. Additionally I have two languages.

    Can anybody tell me how to build a variable path to a linked page.

    For example

    mysite.com/index.php can be accessed from mysite.com/links.php and also from mysite.com/level2/page.php

    and

    mysite.com/_spanish/index.php can be accessed from mysite.com/_spanish/links.php and also from mysite.com/_spanish/level2/page.php

    Any links in /_spanish/ will always point to other files in /_spanish/ and links in the English version will always point to other files in the English version
    Cheers
    Billy

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You can just use an absolute path in the href.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jul 2005
    Posts
    101
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    I can't figure out how to do this because the absolute path will vary depending on where the surfer is when s/he clicks. I've got two copies of each page, one in English the other in Spanish and both use the same navbar.

    So the English index.php is in public_html/ but the Spanish index.php is in public_html/_spanish/

    If the user is in /level1/page.php and clicks on index.php link I need to go up one level but if the user is in links.php and clicks on index.php the level stays the same.

    Basically I need to figure out how deep down the directory tree the user is and therefore how many levels to go up.

    Another problem I had with absolute path was that when I uploaded, the full server path is being included (i.e. levels above public_html) which caused permission problems.
    Cheers
    Billy

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Ah, I see. My initial reaction here is to say that if the sites are the same, but in different languages, you probably should have built your entire structure differently, with only a GET variable's difference. Something like:
    PHP Code:
    if($_GET['lang'] == "es") { require("../_spanish/" $PHP_SELF); die(); } 
    If you'd rather keep your (apparent) directory structure, you can just check for the presence of "_spanish" in the path, and tack on another ../. E.G.:
    PHP Code:
    <a href="<?php echo(strstr($SCRIPT_FILENAME"_spanish") ? "../" $href $href); ?>">
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Jul 2005
    Posts
    101
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Thanks, Twey

    I did the site in HTML originally using a wysiwyg package which had built in support for more than one language. It did this by automatically generating page copies in the second language. I've inherited the structure from then.

    I've gone over to PHP because of the limitations, bu tI've kept the same structure for the time being while I learn. Once I get the nav working from single-copy includes, I'll start on the pages.

    I am already using conditional checks for _spanish in the filename. It did not occur to me to take an absolute path and tag on _spanish if necessary (duhh)

    I was also using $_SERVER['DOCUMENT_ROOT'] instead of $PHP_SELF.

    Thanks again
    Cheers
    Billy

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
  •