Another newbie question
Moderator: General Moderators
-
alex_gmail
- Forum Newbie
- Posts: 4
- Joined: Mon May 25, 2009 5:41 pm
Another newbie question
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
Take a look at your include path. It should resemble
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
will work regardless of where you put it.
Code: Select all
.:/usr/include/phpKeep 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";