No includes on higher directories?

wesley09

New Member
Messages
5
Reaction score
0
Points
0
Need to Know:
http://example.pcriot.com/a/includes/header.php (Would contain the header)
http://example.pcriot.com/a/includes/footer.php (Would contain the footer)
http://example.pcriot.com/a/index.php (The index page of directory A)
http://example.pcriot.com/a/lettera/index.php (Another index of a higher directory)

The Problem:
Okay. It won't display my header and footer even though I correctly use the include function. I've tried everything, but just displays a white page with the text.

Example:
Let's say I make a page with a url of http://example.pcriot.com/a/lettera/index.php.
And I want to include http://example.pcriot.com/a/includes/header.php and http://example.pcriot.com/a/includes/footer.php
So, I would use the PHP include function and use those.
The problem is, the includes won't show up, just the page of /a/lettera/index.php.

Help?
 

Livewire

Abuse Compliance Officer
Staff member
Messages
18,169
Reaction score
216
Points
63
Try this:

include("/a/includes/header.php");

It'll start looking in a/lettera/a/includes/header.php.

Tested this in a localhost testing environment:

Two files, index.php (located in htdocs/gallery1), includer.php (located in htdocs/gallery1/action).

Inside includer.php:

Code:
<?php
include ("../index.php");
?>

Included index.php properly :) For each directory you want to go back "up" on, do ../

So if I need to go up two directorys, "../../Filename"
 

akkudreamz

New Member
Messages
183
Reaction score
0
Points
0
i believe you should always use relative path and not absolute one...you'll notice the reason in time
:)
 

Livewire

Abuse Compliance Officer
Staff member
Messages
18,169
Reaction score
216
Points
63
i believe you should always use relative path and not absolute one...you'll notice the reason in time
:)

QFT; whenever possible don't do absolute.

Seriously; its a pain to migrate from Localhost to <insertdomainhere>.

Heck, it's a pain to move from <insertdomainhere> to <insertdomainhere>/<insertsubfolderhere> :p
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
I like the idea of the includer, but presuambly, if you have different includes for different sections fo the site, you would also need that number of "includer.php" files...?

What I mean is, the standard includes like header, footer etc could go in one includer, but some others like login status for example would only appear on those pages relevant to when you are logged in.

I use DW, so migrating links is simple...... or is it? :)

_____

Edit: just thought - wouldn't you get this problem with the path to the includer?????

Can't get my head around this....
 
Last edited:

Rolus

New Member
Messages
9
Reaction score
0
Points
0
I've had problems with including on higher pads when using require and require_once (which is the same as include with only difference that a fatal error is triggered when the included page isnt found). Ever since I've used require_once(dirname(__FILE__)."/../dirname/foo.php"); making use of the __FILE__ constant. That should work always and on every server setting.
 

digitalsoft

New Member
Messages
1
Reaction score
0
Points
0
Need to Know:
http://example.pcriot.com/a/includes/header.php (Would contain the header)
http://example.pcriot.com/a/includes/footer.php (Would contain the footer)
http://example.pcriot.com/a/index.php (The index page of directory A)
http://example.pcriot.com/a/lettera/index.php (Another index of a higher directory)

The Problem:
Okay. It won't display my header and footer even though I correctly use the include function. I've tried everything, but just displays a white page with the text.

Example:
Let's say I make a page with a url of http://example.pcriot.com/a/lettera/index.php.
And I want to include http://example.pcriot.com/a/includes/header.php and http://example.pcriot.com/a/includes/footer.php
So, I would use the PHP include function and use those.
The problem is, the includes won't show up, just the page of /a/lettera/index.php.

Help?

Hello Wesley,

You need to appropriatley configure your php script to handle top level directories. To navigate upwards in a web server, you use /..

So lets say, for instance. Your webserver is a ROOT level = / , you make a folder called images, so that would look like in the server - /images/

Well, lets say you had a PHP script in a folder called scripts, and it called for one of the images in the images folder, you might be wondering. How would I go upon doing this? Well :) , i'ts simple, just go ../images/imagefile.jpg

It basically tells the server to Go UP one directory, goto the images directory, and access the imagefile.jpg

Hope this clears any misunderstanding. :biggrin:
 
Top