Forum Moderators: coopster
Thanks for your help, we're really getting somewhere!
-- Brett
[php.net ]
Nick
matrym, content of included files is treated as if it were in the original file, so you can of course call the function from anywhere you like.
Thanks for all your help guys!
-- Brett
Actually .inc is not a good idea, because every user can get the source code if he knows the file name
Not so. For security reasons/code protection, your scripts should be above the http root (where your web pages are).
Call the files whatever you like, it really makes no differnce... .inc is just a convention....
As for how to include this file... check the link in my earlier post..
Nick
Thanks,
Brett
matrym: Yes, of course you can leave all the other stuff in file2!
Just do include('file2'); and you can call one, any or all of file2's functions in file1 wherever you like, the usual way, as if all of file2's contents were in file1. Try it out, you'll see how it works.
functions.php
library.inc
purple.green
Then you include this at the top of every file on the site. Naturally, a function that will be used on only one page might or might not go in here depending on whether you want to emphasize run-time efficiency or code reuse.
Tom
I also include the following code in the top of my PHP files with my own custom functions so that if I include the code by accident in multiple files (for example global functions or database setup routines) then the code doesn't cause the dreaded function already defined error.
if(MY_CUSTOM_FUNCTION_MAKELINK==1){
return;
}
define("MY_CUSTOM_FUNCTION_MAKELINK", 1);
Just my 2 cents. I hope my knowledge helps neaten up someone’s code. :)
" The require_once() [php.net] statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the require() statement, with the only difference being that if the code from a file has already been included, it will not be included again."