SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Member DroppedAtBirth's Avatar
    Join Date
    Apr 2001
    Location
    Tempe, Az
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php include() file in sub directory

    I am trying to create a blank page in php-nuke that is in a subdirectory like

    http://www.whatever.com/test/index.php

    If I use the following code I get errors that are because of the includes()'s the header.php and mainfile.php are in the root directory - http://www.whatever.com . Any ideas?

    ---------------code---------------------

    Code:
     
    
    <?PHP
    
    if(!IsSet($mainfile)) { include ("../mainfile.php"); }
    $index = 1;
    //automatednews();
    
    function theindex() {
        global $storyhome, $httpref, $httprefmax, $topicname, $topicimage, $topictext, $datetime, $user, $cookie, $nuke_url;
        include("../header.php");
      /*Content Here*/
     echo("text text");
    //    include("footer.php");
    }
    
    theindex();
    
    ?>

    _________________
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Robert Ward
    webmaster@droppedatbirth.com
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ~~~~~~~~~~~~~~~~~~~~~
    Robert Ward
    webmaster@droppedatbirth.com
    ~~~~~~~~~~~~~~~~~~~~~

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you sure? There doesn't appear to be anything wrong with how you have written those relative paths.

  3. #3
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could do one of two things. First is use a CHDIR to go up one level, or you could use a URL to the file instead of a path.

    First idea:
    CHDIR("../")
    include("header.php");

    Second idea:
    include("http://www.whatever.com/header.php");

    Third idea that I just got:
    include("/header.php");
    (the / means the root)
    Kevin

  4. #4
    Anyone seen my cypher? OneChance's Avatar
    Join Date
    Apr 2001
    Location
    Seattle
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There may be a better way, but here's how I do it:
    PHP Code:
    include($DOCUMENT_ROOT "header.php"); 

  5. #5
    SitePoint Member DroppedAtBirth's Avatar
    Join Date
    Apr 2001
    Location
    Tempe, Az
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have actually tried most of thoses ideas. The only one that worked is adding

    CDDIR("../");

    to the following line
    Code:
    if(!IsSet($mainfile)) { CHDIR("../"); include ("mainfile.php"); }
    Thanks all
    ~~~~~~~~~~~~~~~~~~~~~
    Robert Ward
    webmaster@droppedatbirth.com
    ~~~~~~~~~~~~~~~~~~~~~

  6. #6
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Generally you should pick a particular directory to contain your include files and add it to the php_include variable in your php.ini file. Then you don't have to worry about relative paths or anything when including -- you just give the file name and PHP will find it.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  7. #7
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    try this

    I have all my included files in the folder "includes" in my root directory. so I always do this
    PHP Code:
    include("$DOCUMENT_ROOT/includes/thefileIwant.php"); 
    that way you can get at anyfile, just look for it from the top of you server.

  8. #8
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by kyank
    ...and add it to the php_include variable in your php.ini file.
    Given the popularity of the web hosting forum, I would venture to say a majority of users here can't access/edit their php.ini file because they are on shared hosting.
    Kevin

  9. #9
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    In that case, Snoozy's solution above works just as well.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  10. #10
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure does.

    I use a subdomain for all my includes, and I have a page template set up in EditPlus, so I just start a new page via that and the include tags are already there.
    Kevin

  11. #11
    SitePoint Member DroppedAtBirth's Avatar
    Join Date
    Apr 2001
    Location
    Tempe, Az
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is the variable $DOCUMENT_ROOT a pre defined variable?? Because I tried /home/user/public_html/ but that did work. Haven't tried the $DOCUMENT_ROOT/.... one.

    Just figured I would ask. Still learning php and mysql.

    Thanks.
    ~~~~~~~~~~~~~~~~~~~~~
    Robert Ward
    webmaster@droppedatbirth.com
    ~~~~~~~~~~~~~~~~~~~~~

  12. #12
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It's an environment variable set by your Web server. Some Web servers do not set that particular variable, and the CGI version of PHP will not have it. In cases like that, you'll either have to hard-code the variable yourself or come up with an alternate way of producing it.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference


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
  •