Page 1 of 1

Include() statement

Posted: Tue Feb 28, 2006 3:17 pm
by Michael_C
Another newbie question.
I've been looking at code in hopes to understand an existing website.
There are some buttons and text displayed on web pages, that appear to be generated from a file called template_1.html, but the only reference to template_1.html is in an include() in another file.

One thing that is puzzling could be answered if the include() not only "pulls" in the code/script from the file being included, but also executes it.

The PHP manual states "The include() statement includes and evaluates the specified file".

What does "evaluates" mean - "execute", or ...?

Normally I would have assumed the include() would work as it does in many languages - e.g., a directive to treat the contents of the "included" file as if it appeared in the php program.

If the code isn't executed in the include file then I'm back at square one trying to figure how some sections on a web page are generated/displayed.

Thanks in advance,

Michael

Posted: Tue Feb 28, 2006 3:18 pm
by feyd
Moved to PHP - Code. :roll:

Posted: Tue Feb 28, 2006 3:19 pm
by neophyte
The included file may or may not contain PHP so it evaluates whether the file has PHP executes those portions and skips the rest.

Posted: Tue Feb 28, 2006 3:39 pm
by John Cartwright
think of including a file as in copy and pasting that particular file directly into the script.. any variables within that script can be carried over and such.

Posted: Tue Feb 28, 2006 4:30 pm
by Michael_C
Jcart wrote:think of including a file as in copy and pasting that particular file directly into the script.. any variables within that script can be carried over and such.
Then the code in the included file is "available", and can be called, but just having the include() won't cause the code to be executed.

Here is the crux of what I'm trying to understand:

There is a file "http://TheWebSite/dreamaccount/Members.htm with the following link:
href="http://TheWebSite/dreamaccount/">CLICK HERE TO LOGON TO MEMBERS AREA</a></span></b></p>

When you clicks on the link a web page is displayed that looks like the content is from:
//TheWebSite/dreamaccount/Member_main.html and
//TheWebSite/dreamaccount/template_1.htm

I'm assuming when the user click on the link //TheWebSite/dreamaccount/index.php is run
the last line in index.php is:
include($path . '' . TEMPLATE_FILE);

I have no idea why Member_main.html, nor template files are executed.

I can't find a single "call" to Member_main.html in any file, and the only reference to the template file is via the include.

Any thoughts?

Michael
PS. I want to understand how/why things are working currently before I carve into things. I need to hook into the existing code in this general area - from there, I plan to do most, if not all, the work in Php.

Posted: Tue Feb 28, 2006 4:43 pm
by neophyte
See if you can find where TEMPLATE_FILE is defined. It should be a line of code like:

Code: Select all

define('TEMPLATE_FILE', 'somefile.ext');
//where some file.ext is the file you suspect is included.

Posted: Tue Feb 28, 2006 5:12 pm
by Michael_C
neophyte wrote:See if you can find where TEMPLATE_FILE is defined. It should be a line of code like:

Code: Select all

define('TEMPLATE_FILE', 'somefile.ext');
//where some file.ext is the file you suspect is included.
The define is:

Code: Select all

define("TEMPLATE_FILE", $dbs->f("setup_template_file"));
and the setup_template_file field in Setup table is set to template_1.html

and again, the last line in index.php is:

Code: Select all

include($path . '' . TEMPLATE_FILE)
;


What I'm trying to figure out:
how does the Template file Html get executed - the last line in index.php wouldn't do it (or would it?)
how does the member_main.html get called

And finally, is my assumption correct - will index.php, in dreamaccount folder, be executed if link href="http://TheWebSite/dreamaccount/ is clicked?

Michael

Posted: Tue Feb 28, 2006 5:21 pm
by John Cartwright
Then the code in the included file is "available", and can be called, but just having the include() won't cause the code to be executed.
Any php code included will be executed in the order that it is included.

for instance..

page1.php

Code: Select all

echo 1;
page2.php

Code: Select all

echo 2;
page3.php

Code: Select all

echo 3;
index.php

Code: Select all

include('page1.php');
include('page2.php');
include('page3.php');
This would output

Code: Select all

123
And finally, is my assumption correct - will index.php, in dreamaccount folder, be executed if link href="http://TheWebSite/dreamaccount/ is clicked?
Correct.

Posted: Tue Feb 28, 2006 5:32 pm
by Fractal
Michael_C wrote:And finally, is my assumption correct - will index.php, in dreamaccount folder, be executed if link href="http://TheWebSite/dreamaccount/ is clicked?

Michael
Only if the server's default page is index, this could be changed to default, home, or whatever you want.

Usually it searches for [default_page].html or [default_page].htm first, if those don't exist it then searches for [default_page].ext, ext being php, asp, cf, or whatever language you are using.

Posted: Tue Feb 28, 2006 5:57 pm
by John Cartwright
Usually it searches for [default_page].html or [default_page].htm first, if those don't exist it then searches for [default_page].ext, ext being php, asp, cf, or whatever language you are using.
I'm pretty sure apache by default includes these, in this order

Code: Select all

DirectoryIndex index.php index.html index.htm

Posted: Tue Feb 28, 2006 6:02 pm
by feyd
depends on installation...

Posted: Tue Feb 28, 2006 6:02 pm
by Michael_C
Thank you for both the confirmation and clarification on include() - your example showed how the 3 php files would be executed when index.php was run - does this apply to html files as well? Would page2.html execute if index.php had the following:

Code: Select all

include('page1.php'); 
include('page2.html'); 
include('page3.php');
if so, that explains how the Template.html content is displayed. The only mystery, to me, is how member_main.htm is invoked.

Any suggestions on where to look for member_main.htm - I've done a search of all files for "member_main" with no success. Any other places to check in the php environment?

Thanks again,

Michael