SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    TEMP url with $_SERVER['DOCUMENT_ROOT'] = Error!

    I'm working with PHP and when I include a file using $_SERVER['DOCUMENT_ROOT'] on the domain, or a sub domain the include works wonderfully.

    But when I use the temp URL I get this error

    Warning: include(/usr/local/apache/htdocs/test1.php) [function.include]: failed to open stream: No such file or directory in /home/jtiger/public_html/test.php on line 3

    Warning: include() [function.include]: Failed opening '/usr/local/apache/htdocs/test1.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/jtiger/public_html/test.php on line 3

    BUT if I was to use this absolute path in the include it works.
    /home/jtiger/public_html/test1.php

    As you can figure, that is a major issue if I was to move this site form a domain to a temp url. And I want to use the Temp URL for I can use a shared SSL with it.

    Here is my code that causes the error.
    include $_SERVER['DOCUMENT_ROOT'] . '/test1.php';

    Here is the code that works
    include '/home/jtiger/public_html/cms/includes/db.inc.php';


    Best I can figure, the Doc_root is calling a different file path than the absolute path
    /usr/local/apache/htdocs/test1.php Error
    /home/jtiger/public_html/test1.php Works

  2. #2
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You probably want to use $_SERVER['HTTP_HOST'] or $_SERVER['SERVER_ADDR'].

    Try
    PHP Code:
    echo "<pre>\n";
    print_r ($_SERVER);
    echo 
    "</pre>\n"
    to see what works for you.
    Denny Schlesinger
    web services

  3. #3
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,319
    Mentioned
    462 Post(s)
    Tagged
    8 Thread(s)
    It looks like your temporary location is on your local computer? Are you using something like XAMPP or MAMP? You can set things up locally to work the same as on your server.


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
  •