PDA

View Full Version : PHP includes


Mixi
March 26th, 2007, 06:05 PM
Does anybody know a good tutorial for using php includes with a direct path instead of in each folder? I saw a code that said u can just create a folder and put all your includes in it and then just use that one code but you need root access and for the site I want to use it on I dont have root access. If anybody has any tips I'd appreciate it.

omen
March 26th, 2007, 06:52 PM
/home/bla/public_html/inc/file.php

or /www/accountnumb/htdocs/

It's different for your server, but you should be able to work it out.

George
March 26th, 2007, 07:51 PM
You don't need root access.

http://www.georgeboone.com/the-power-of-the-php-include/

Mixi
March 26th, 2007, 09:20 PM
You don't need root access.

http://www.georgeboone.com/the-power-of-the-php-include/

thats just a regular php include. I have like a 100 folders and Its time consuming to change the header and the footer inside every folder. I just want to create a folder and have all the includes direct link to that 1 folder.

Like url.com/Includes/header.php so that I would only have to change that one file instead of a 100 . I saw a tut before but it said you needed root access for it and on the site im doing this on I only have access to the main index part

SamOwen
March 26th, 2007, 11:05 PM
thats just a regular php include. I have like a 100 folders and Its time consuming to change the header and the footer inside every folder. I just want to create a folder and have all the includes direct link to that 1 folder.It's as simple as doing what you just said.

Create a folder to house all your included files.
Upload all your "include" files into that folder.
In your PHP page/script call any "include" files from that folder.

Greg-J
March 27th, 2007, 12:23 AM
includes are relative.

So if you're 3 folders past your /includes folder you'll need to start your include path off with ../../../

Alternatively you might just want to find out what your current directory is as omen mentioned, but there is an easier way.

Use the global variable $_SERVER["DOCUMENT_ROOT"] rather than hard coding the base path to your includes. This way if you move your site to another server you aren't stuck with a mass search & replace.

Mixi
March 27th, 2007, 03:30 AM
thanks everybody I'll try and see how it goes

YabbaDoo
March 27th, 2007, 05:31 AM
includes are relative.

So if you're 3 folders past your /includes folder you'll need to start your include path off with ../../../

Alternatively you might just want to find out what your current directory is as omen mentioned, but there is an easier way.

Use the global variable $_SERVER["DOCUMENT_ROOT"] rather than hard coding the base path to your includes. This way if you move your site to another server you aren't stuck with a mass search & replace.

Good tips there!
Cheers!