Functions File?

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
User avatar
tmaiden
Forum Commoner
Posts: 64
Joined: Fri Feb 24, 2006 3:15 pm
Location: Philadelphia
Contact:

Functions File?

Post by tmaiden »

I understand how templates work. Where I can include a block of html, rather then having to hardcode it into each page.
Example: include 'templates/header.php';

Now lets say I have some functions that I want to include into each page, how do I do this?

When I try to do so, I get this error.
Fatal error: Cannot redeclare html2txt() (previously declared in /.../addperson.php:4) in /.../config.php on line 21

How do I work around this; rather then just answer, any tutorials or anything like that would be great. Not too sure what topic this would fall under so I'm having trouble researching it.

THANKS!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Function are not defined per file but per php instance. There's obviously no need to include addperson.php again - the functzion is still known to php.
If you do not want to keep track yourself try require_once
User avatar
tmaiden
Forum Commoner
Posts: 64
Joined: Fri Feb 24, 2006 3:15 pm
Location: Philadelphia
Contact:

Post by tmaiden »

Since each page on my site has:
include('config.php');

Should I put require_once('functions.php'), into config.php OR in each page do:
include('config.php');
require_once('functions.php');

Thanks again, volka
Post Reply