Results 1 to 15 of 15
  1. #1
    Join Date
    Sep 2002
    Location
    az
    Posts
    168

    including file for links

    Hey, im trying to do something where i include an html file with php using this line
    PHP Code:
    <? include ("/www/www.flashstand.com/links.html"); ?>
    Ive tried the following:
    ../links.html
    /links.html but they all fail
    is it my php mabye? thanks fior the help,
    -Mike

  2. #2
    Join Date
    Dec 2001
    Location
    New Hampshire
    Posts
    93
    where're you tryinna include this from?
    evidently, this is your document root;
    if that's the case, you can use
    PHP Code:
    <?include("$DOCUMENT_ROOT/links.html");?>
    /*if the calling document is in the CWD, you can just do */
    <?include("./links.html");?>
    WYSIWYG

  3. #3
    Join Date
    Sep 2002
    Location
    az
    Posts
    168
    its not in the same directory.... so which one should i use?

  4. #4
    Join Date
    Sep 2002
    Location
    az
    Posts
    168
    errrr it said..

    Notice: Undefined variable: DOCUMENT_ROOT in D:\www\www.flashstand.com\dl\index.php on line 48

    Warning: Failed opening '/links.html' for inclusion (include_path='.;c:\php4\pear') in D:\www\www.flashstand.com\dl\index.php on line 48

  5. #5
    Join Date
    Dec 2001
    Location
    New Hampshire
    Posts
    93
    oh yeah, before you can use $document_root you must
    PHP Code:
    global $HTTP_SERVER_VARS;
    /*then document_root will be defined*/
    <?include("$DOCUMENT_ROOT/links.html");?>
    /*[EDIT='this line was way too long']
    I have global $HTTP_SERVER_VARS; 
    included before anything else 
    so I can do things like that anywhere 
    without needing to think about it 
    which is why I didn't think to include it before.. 
    please excuse me for my apparent ignorance[/EDIT]*/
    well what directory is it in? Relative URLs should work as should anything that uses the filesystem structure
    e.g.:
    PHP Code:
    <? include ("/www/www.flashstand.com/links.html"); ?>
    /* or */
    <?global $HTTP_SERVER_VARS;
    include(
    "$DOCUMENT_ROOT/links.html");?>
    /* or */
    <?include("../../links.html");?>
    /* (but only if the calling page is two directories below the 'links.html' file) */
    /* BUT NOT */
    <?include("http://www.flashstand.com/links.html"); ?>
    WYSIWYG

  6. #6
    Join Date
    Sep 2002
    Location
    az
    Posts
    168
    I think on the server, Global Variables are turned off. Do I need direct access to the server to turn them on?! Also, I tried the first method, it didn't work. And the 2nd one I think i need Global Variables to be turned on. And links.html is in the base directory. Thanks.
    Mike

    Edit: The server is windows if this means anything
    Last edited by brcolow; 09-15-2002 at 04:11 AM.

  7. #7
    Join Date
    Sep 2001
    Location
    Pune, Maharashtra, India.
    Posts
    24
    $_SERVER['DOCUMENT_ROOT']

    Use that.

  8. #8
    Join Date
    Sep 2002
    Location
    az
    Posts
    168
    i did this....

    PHP Code:
    <?include("$_SERVER['DOCUMENT_ROOT']/links.html");?>

    Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in D:\www\www.flashstand.com\dl\index.php on line 48

    did i type that wrong?

  9. #9
    Join Date
    Sep 2002
    Location
    az
    Posts
    168
    bump

  10. #10
    Anytime you use '/something' whether it's a link, image, or whatever, '/' refers to the root dir of the site.
    But obviously that doesn't work... so I don't know...
    Is the file you want to inclue above or below the index.php ?
    Last edited by Alturus; 09-15-2002 at 05:28 PM.
    http://www.alturus.ca
    Professional Web-Design/Programming

    Your CSS2.0/XHTML table-less guru. Pushing for properly coded webpages.

  11. #11
    <?include("$_SERVER['DOCUMENT_ROOT']/links.html");?>

    <?php include ("/home/devimgc/incs/global/globalheader.php"); ?>

    First you're missing spaces, and not telling the server to parse it.
    dotGig
    <:<: [Fruit eating linux administrator]

  12. #12
    Join Date
    Sep 2002
    Location
    az
    Posts
    168
    ok... well i have alot of index.php's but the main one (thre homepage) i think is the one ur talking about, and links.html is in the SAME directory, but the pages i want to use it on are ALL below the directory....thanks
    -Mike

  13. #13
    Join Date
    Sep 2002
    Location
    Minnesota
    Posts
    65
    If the file you are loading (index.php) and the file you are trying to include (links.html), I don't think you need to note anything with your root folder. Just use relative paths: <?*include*("/links.html");*?>. This will load links.html from the home directory (the base web folder). I may be misunderstanding the problem, or maybe it's different on a Windows machine ...

  14. #14
    Join Date
    Dec 2001
    Location
    New Hampshire
    Posts
    93
    PHP Code:
    <?
    /* like you said before, */
    include("$_SERVER['DOCUMENT_ROOT']/links.html");
    /* only you should define first, else, 
    like Samuel said "not telling the server to parse it." 
     the server doesn't know that what $_SERVER['DOCUMENT_ROOT'] is until it's too late.
    THEN, you can use it like: */
    $docroot $_SERVER['DOCUMENT_ROOT'];
    include 
    $docroot."/links.html";
    /* or simply, like AboveCenter said, */
    include "/links.html";
    /*but, like you said "is it my php mabye?",
     I just upgraded to 4.2.2 from 4.1.3 and I think including
    something that starts with "/" doesn't seem to work correctly in
    an older version (but now I don't remember already) so maybe
    you should define it, as in '$docroot' before or one of the methods below.
    if you happen to be including something from the same directory
    as the document you're including at some point, do it like this */
    include "./included_document_filename.ext";
    /* or, if you're including at a predetermined relative distance above in the directory structure, (i.e. 2 folders above) */
    include "../../included_document_filename.ext";
    /* and if you want to include something from a directory below, */
    include "foldername/path/to/included_document_filename.ext";
    /*
    and you said "Global Variables are turned off. Do I need direct
    access to the server ", and I say */
    $url="http://www.php.net/manual/en/function.ini-set.php";
    /* or, add to .htaccess (or maybe.. windows... :rolleyes: ) 
    php_value register_globals 1*/
    ?>
    [EDIT]manual linewrap[/EDIT]
    Last edited by prosayist; 09-17-2002 at 12:38 AM.
    WYSIWYG

  15. #15
    Join Date
    Sep 2002
    Location
    az
    Posts
    168
    makes me laugh, i go it to works the f**ing slahses were backwards LOLOL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •