A Stupid Question (I hope...)

Discussion in 'Web Design and Development' started by MegaMan1311, Jun 20, 2008.

  1. MegaMan1311 macrumors regular

    Joined:
    Jun 30, 2007
    Location:
    USA
    #1
    Hello.

    I am developing a template for my site and I have what I hope is a stupid question involving links. But first, let me give you my site's folder architecture.

    HTML:
    root/
       index.php
       includes/
          myinclude.php
       news/
          index.php
    And so on and so forth.
    I have two content pages. root/index.php and news/index.php.

    Each of the pages have includes linking to myinclude.php. All three of the pages need to have the same code, excluding the content region of course.

    Now then, in the root/index.php file, I link to the includes using
    PHP:
    <?php include("includes/myinclude.php"); ?>
    In the news/index.php, I like to the includes using
    PHP:
    <?php include("/includes/myinclude.php"); ?>
    How can I change that code so that the code to get to the includes is the SAME for both the root/index.php and the news/index.php? Does that make sense? Thanks in advance.
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    Yup, stupid question ;) You're thinking too hard. Just use the second method you have posted as it is an absolute server path and will work from anywhere in your directory tree.
     
  3. MegaMan1311 thread starter macrumors regular

    Joined:
    Jun 30, 2007
    Location:
    USA
    #3
    Ahh... I had tried that before, but it didn't work. I figured out why though. It is because of my testing server (MAMP) and this site is located in a folder in that server. Duh... I feel stupid now. :)

    Here is one more question though. On a server with the following setup, would it still work? (I don't have a remote testing server set up yet). I just got my own server that isn't shared hosting, so I'm still knew with servers...

    Code:
    root/
        serverfiles/
        httpdocs/
            index.php
            rest of my files
        moreserverfiles/
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    It'll depend on the Apache configuration. There's a line similar to,

    <Directory "/Applications/MAMP/htdocs">

    which is the document root and any references like /fileorfolder will start from that folder. So for your case that document root would likely be for the httpdocs folder (if I understand what you put there). Does that clear it up?
     
  5. MegaMan1311 thread starter macrumors regular

    Joined:
    Jun 30, 2007
    Location:
    USA
    #5
    Yeah. I understand. I'm pretty sure that it is considering the httpdocs folder as the document root. Thanks.
     

Share This Page