Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MegaMan1311

macrumors regular
Original poster
Jun 30, 2007
216
0
USA
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.
 
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.
 
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/
 
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?
 
Yeah. I understand. I'm pretty sure that it is considering the httpdocs folder as the document root. Thanks.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.