PDA

View Full Version : A Stupid Question (I hope...)




MegaMan1311
Jun 20, 2008, 06:43 PM
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.

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 include("includes/myinclude.php"); ?>

In the news/index.php, I like to the includes using <?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.



angelwatt
Jun 20, 2008, 06:48 PM
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.

MegaMan1311
Jun 20, 2008, 07:14 PM
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...

root/
serverfiles/
httpdocs/
index.php
rest of my files
moreserverfiles/

angelwatt
Jun 20, 2008, 07:31 PM
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?

MegaMan1311
Jun 20, 2008, 07:33 PM
Yeah. I understand. I'm pretty sure that it is considering the httpdocs folder as the document root. Thanks.