the include statement

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
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

the include statement

Post by Charles256 »

does it cause the entire page currently being viewed to load again?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

huh?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

example

Code: Select all

<body>
blah blah blah
<?php
switch ($case)
{
 case "blah":
 include ("blah.php");
 break;
}
?>
more blah html
after clicking a link to make case equal to blah does it then reload the html code on the page?or just insert the code from blah.php?:)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

both.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

Whenever a page loads, a page loads. php works like this:

1. user variables are defined (get, post, cookies, session, server).
2. it runs the script from top to bottom.

Examples:

Code: Select all

<?php
// file1.php
echo "file 1 output\n";
if (isset($_GET['two'])) {
  include 'file2.php';
}
?>

Code: Select all

<?php
// file2.php
echo "file 2 output\n";
?>
When you include a file, it's the same thing as if that file were physically there. include() is there simply so you can split your code into separate files. The above two files are exactly (sorta) like the following:

Code: Select all

<?php
// file3.php
echo "file 1 output\n";
if (isset($_GET['two'])) {
  echo "file 2 output\n";
}
?>
I always see some form of this question about the include() family of statements, and this explanation always seems to help. ;)
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

i was comparing the iframe to the include and it seems iframe would save loading time :-D
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

iframes aren't the best solution. Many users don't enable frames on webpages because they generally suck.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

then i do the following .. <iframe blah>Enable frames or face dire consequences </iframe>
problem solved:)
Post Reply