Include() statement
Moderator: General Moderators
Include() statement
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
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
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
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.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.
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.
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: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.
Code: Select all
define("TEMPLATE_FILE", $dbs->f("setup_template_file"));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
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Any php code included will be executed in the order that it is included.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.
for instance..
page1.php
Code: Select all
echo 1;Code: Select all
echo 2;Code: Select all
echo 3;Code: Select all
include('page1.php');
include('page2.php');
include('page3.php');Code: Select all
123Correct.And finally, is my assumption correct - will index.php, in dreamaccount folder, be executed if link href="http://TheWebSite/dreamaccount/ is clicked?
Only if the server's default page is index, this could be changed to default, home, or whatever you want.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
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.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
I'm pretty sure apache by default includes these, in this orderUsually 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.
Code: Select all
DirectoryIndex index.php index.html index.htmThank 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:
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
Code: Select all
include('page1.php');
include('page2.html');
include('page3.php');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