php include 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
kuhlpal
Forum Newbie
Posts: 10
Joined: Wed Oct 22, 2008 3:56 pm

php include file

Post 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.
Hannes2k
Forum Contributor
Posts: 102
Joined: Fri Oct 24, 2008 12:22 pm

Re: php include file

Post 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.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: php include file

Post 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".
kuhlpal
Forum Newbie
Posts: 10
Joined: Wed Oct 22, 2008 3:56 pm

Re: php include file

Post 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.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: php include file

Post by califdon »

The same comments each of us gave you still applies. Please read what we have already told you.
Post Reply