PHP and ASP Includes
PHP and ASP are both very powerful server side scripting languages (SSL) that can add a lot of versatility and functionality to a website. You don’t have to understand much programming, however, to make use of one of their most handy components, include statements. Which language you use depends on what type of server your site is hosted on.
PHP Include
<?php include(”header.inc”); ?>
ASP include
<!––#include file=”info_header.inc”––>
Include statements allow you to place part of your code into a separate document that can then be included on multiple pages of your website. The advantage is that you can include all you your
details, logo, links, and so forth in one file. Then, if you need to update anything in that section, all of the pages including that file are automatically updated. You can also do the same for the footer.Since these included files are simple text documents, they can have whatever extension you want, but commonly end in .inc. When read by a browser, the included file is read as part of the initial page. That is, the browser sees header.inc, index.php (or .asp), and footer.inc as one document.
The procedure is pretty straightforward, but here are some basic examples to get you started. The following examples are in PHP, but the ASP would work exactly the same with the appropriate include statement.
header.inc:
<html>
<head>
<title>Include Example</title>
</head>
<body>
<div id=”nav”">
<ul>
<li><a href=”books.php”>Favorite Books</a></li>
<li><a href=”movies.php”>Favorite Movies</a></li>
<li><a href=”other.php”>Other Favorites</a></li>
</ul>
</div>
index.php:
<?php include(”header.inc”); ?>
<div id=”content”>
<h1>Title</h1>
<p>Some content.</p>
</div>
<?php include(”footer.inc”); ?>
footer.inc:
<div id=”footer”>
Copyright info
</div>
</body>
</html>
I just wanted to point out the big difference between php and asp includes (because I don’t think I can find a better spot for this snippit of info.)
In php, you can assign a dynamic variable as the target of the include function. For example…
$fileName = "header_public.inc";
include(fileName);
?>
In asp however, since includes are not within the asp tags ( <% and %> ), the following would NOT work…
<%
fileName = "header_logged.inc"
%>
You have a lot less flexability when using asp includes, but they stil serve their purpose.
Comment by chris — November 20, 2006 @ 5:36 pm