SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict revlimiter's Avatar
    Join Date
    Sep 2005
    Location
    British Columbia, Canada
    Posts
    275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Includes - $_SERVER['DOCUMENT_ROOT'] for Temporary URL and Live URL?

    Hey everyone,
    I have an issue with how the PHP includes are being picked up on my temporary URLs http://IPADDRESS/~USERNAME/SITENAME/ compared to my live URL http://LIVEDOMAIN.com

    The PHP code that I am using is
    ? include($_SERVER['DOCUMENT_ROOT'] . '/inc/php/header.php'); ?>

    and it works great on the live domain because I guess it picks up the DOCUMENT_ROOT as the folder I set that domain up to be in cPanel?

    But when I try to load the site on my temporary URL it says that it can't find the PHP include.

    I'm on a shared host and I am the owner of many websites which is why they are within my username and sitename folders like that. Should I be using something else other than DOCUMENT_ROOT in order to view both the temporary URL and the live URL correctly?

    Hope that makes sense!

    Thanks,
    "To make an apple pie from scratch,
    you must first create the universe.
    -Carl Sagan

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,299
    Mentioned
    460 Post(s)
    Tagged
    8 Thread(s)
    Yes, the document root is in a different location in that scenario. My solution to this is to place sites temporarily in a subdomain. E.g. client.mydomain.com

  3. #3
    SitePoint Addict revlimiter's Avatar
    Join Date
    Sep 2005
    Location
    British Columbia, Canada
    Posts
    275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    Yes, the document root is in a different location in that scenario. My solution to this is to place sites temporarily in a subdomain. E.g. client.mydomain.com
    How would subdomains work for temporary URLs though?
    Wouldn't my temporary URL be my shared host IP + username?

    In this case http://50.97.101.243/~username/
    "To make an apple pie from scratch,
    you must first create the universe.
    -Carl Sagan

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,299
    Mentioned
    460 Post(s)
    Tagged
    8 Thread(s)
    If you are allowed to set up a subdomain on your own site (and most hosts will let you do that) you could set up a test site at an address like http://dev.mysite.com. Uploading your files there will mean that they will have their own root folder and everything will work as it will when the site is loaded to its final destination.


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
  •