Welcome to WebmasterWorld Guest from 126.96.36.199
Thanks for your help, we're really getting somewhere!
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!
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..
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.
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.
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.
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."