Results 1 to 4 of 4

Thread: How to do correct path?

  1. #1
    Join Date
    Jan 2006
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to do correct path?

    I have many folders and subfolders on server. As I would like to add code on each page to detect server URL, I need help with this.

    Code is: $_PATH1="http://" . $_SERVER['HTTP_HOST']."/";
    Why I have to add on link for images also / that it will work as it is already there / in

    Link is like. <img src="<?=$_PATH1?>images/myimage.jpg" ></a>

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    I'm not 100&#37; sure what you are asking, but you could try changing $_PATH1 to simply $path like so:

    Code:
    $path = "http://" . $_SERVER['HTTP_HOST']."/";
    then in your link make it like so:

    Code:
    <img src="<?=$path;?>images/myimage.jpg">
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Make sure your server enables the <? shortcut, as opposed to the formal <?php.
    - Mike

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

    Default

    Or just do <?php echo $path; ?> instead of using the short form. thetestingsite, to improve portability of your code, you shouldn't use short forms of tags in any code intended to run on an unknown server (and it's good practice to avoid it in your own, too, in case you want to move some day).
    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!

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
  •