Forum Moderators: coopster

Message Too Old, No Replies

Creating a "global" function

Question from a Perl guy not used to this embedded stuff

         

nysus1

6:35 pm on Aug 1, 2003 (gmt 0)

10+ Year Member



I've got at least 100 web pages which will all be using the same PHP function. I obviously want to avoid pasting this function on every single page. I'm guessing there must be a way to place the function into an external file and then call it from the PHP page. How do you do it?

Thanks!

claus

6:42 pm on Aug 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's a pointer to another thread which might lead you in the right direction:

[webmasterworld.com...]

/claus

<edit>
ah, i see it wasn't perl anyway, that was what caught my eye, sorry. The includestuff might be relevant for php-includes as well, at least i hope so
</edit>

nysus1

6:47 pm on Aug 1, 2003 (gmt 0)

10+ Year Member



I see there is an include() function to do the trick. I'm all set. Thanks.

vincevincevince

7:57 pm on Aug 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



a useful function is: include_once() - which will avoid getting errors if you accidently include() twice and try to declare the function again.

daisho

2:48 pm on Aug 2, 2003 (gmt 0)

10+ Year Member



include_once is very handy before that I always did it the C way which works 100%.

ie:
<?
if!defined( "__TEST_PHP_ALREADY_INCLUDED" ) {
define("__TEST_PHP_ALREADY_INCLUDED",1);

.
.
.
All your PHP
.
.
.

}
?>

Just make sure the id is unique. That way if you do include it twice your safe. Anyways now that I know of include_once that's the way I'm starting to go...