SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamic URL for includes

    I'm including my header in every page of my site and I would like a way to dynamically make sure its always working without changing anything. I was using:
    PHP Code:
    $doc_root $_SERVER['DOCUMENT_ROOT'];
    include_once (
    "$doc_root/includes/header.php"); 
    but since my site is in a sub domain it doesn't work. It works locally because its in the DocumentRoot but when I upload it to my remote site in the sub domain it skips over some of the folders because document_root only returns the address up to the DocumentRoot. Is there a better way to do this?

  2. #2
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use the absolute file path, or add the absolute path to your INCLUDE_PATH.

  3. #3
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php

    #Subdomain
    $root dirname($_SERVER['DOCUMENT_ROOT']) . '/';
    include(
    $root 'includes/file.ext');
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  4. #4
    An average geek earl-grey's Avatar
    Join Date
    Mar 2005
    Location
    Ukraine
    Posts
    1,403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can have a constant on top of each file, like:
    PHP Code:
    $root_path '../'// Script root directory is one level higher 
    Such technique is used by phpBB.

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for all of the help. I am going to try these out and get back to which one works the best for what I am looking for. Thank you.


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
  •