Page 1 of 1
php include file
Posted: Fri Nov 21, 2008 2:19 pm
by kuhlpal
Hi everyone,
I am a Novice and still learning php. Can any one please tell me that to i have written a php function to update datebase in "file1.inc" and i am doing include_once "file1.inc" in "file2.php" then is it sufficient to execute the function or i need to call that function explicitly. I know its a stupid question but does the include_once execute the script of file1 on its own.
Thank you in advance.
Re: php include file
Posted: Fri Nov 21, 2008 2:31 pm
by Hannes2k
Hi,
putting php code into .inc isn't advise, because on many webservers everyone can see the content of .inc files and so gets the php code of your site (and maybe the password for your database).
If you include a file (file1.inc.php), you can use each function which was declared in the included file (file1.inc.php). You have also the access to all variables from file1.inc.php.
Re: php include file
Posted: Fri Nov 21, 2008 2:47 pm
by califdon
kuhlpal wrote:Hi everyone,
I am a Novice and still learning php. Can any one please tell me that to i have written a php function to update datebase in "file1.inc" and i am doing include_once "file1.inc" in "file2.php" then is it sufficient to execute the function or i need to call that function explicitly. I know its a stupid question but does the include_once execute the script of file1 on its own.
Thank you in advance.
It depends on what you have put into your include file. If it is function definitions, then of course you have to call those functions, but if it is just inline code, it will be executed as written. Basically, "include" or "require" just insert the contents inline where you use the "include" or "require".
Re: php include file
Posted: Fri Nov 21, 2008 3:23 pm
by kuhlpal
Hi califdon and Hannes2k,
Thank you for the reply. I understand what you two are doing. But i am unable to call that function as my file2.php contains the code for a pdf and by calling the function of file1.inc, i am getting an error msg. What if i do the following:
include "file1.inc" in file2.php
Do i need to call the function in this case too.
Re: php include file
Posted: Fri Nov 21, 2008 5:35 pm
by califdon
The same comments each of us gave you still applies. Please read what we have already told you.