Page 1 of 1

Another newbie question

Posted: Mon May 25, 2009 7:34 pm
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.

Re: Another newbie question

Posted: Mon May 25, 2009 9:08 pm
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.