Another newbie question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alex_gmail
Forum Newbie
Posts: 4
Joined: Mon May 25, 2009 5:41 pm

Another newbie question

Post by alex_gmail »

I want to put some commoly used self written php code as functions in a file and call them when needed from various php pages. How can I do this? I tried include but that did not work.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Another newbie question

Post by requinix »

Take a look at your include path. It should resemble

Code: Select all

.:/usr/include/php
If you want to include a file then one of those include paths plus the path you give include() should locate your file.
Keep in mind that . is the current working directory, which is not necessarily the directory of the current PHP file.

Or you can use absolute paths. $_SERVER["DOCUMENT_ROOT"] is your web root, so

Code: Select all

include $_SERVER["DOCUMENT_ROOT"] . "/path/to/file.php";
will work regardless of where you put it.
Post Reply