Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INCLUDE STATEMENT

Status
Not open for further replies.

ITGL72

MIS
Jul 2, 2001
105
US
I have done very basic coding with cold fusion in the past. I plan in the future to learn some basic PHP and MySQL too. But for right now I have to get some things going now.

In CF there was a tag called CFINCLUDE, it included part of a page on all pages you used that tag on. Like one piece of code to show the links for the site, etc, Im sure there is a way to do this in PHP too.

Can someone just run the quick and dirty code for doing such a thing on a PHP enabled web host to me?

PS: I know this is a bit of a cheat, but are there any programs that generate PHP code for you? I don't usually like such programs but in this case since I currently know nothing about PHO code I figure it a good question, also a PHP/MySQL book for dummies recommendation too.

Thanks to all!
 
The PHP function that you want to use is include(). This function includes and evaluates the specific file. If the file contains just HTML, then the HTML will be displayed. If the file contains code and/or HTML, then the code will be parsed and the HTML will be displayed.

example:
you have a file called header.html and a file called footer.html. Each file contains just HTML that you want displayed at the head of each page (header.html) and the bottom of each page (footer.html). To add these to each PHP page you would do the following:

somepage.php
Code:
<?
include '/path/to/files/header.html';
?>

Page specific HTML

<?
include '/path/to/files/footer.html';
?>

The same would go for custome PHP function that you may use in several programs. I have several files that contain nothing but functions. If I want to use one of those, I just include the file that contains that code.

example:
I have a file called nocache.inc that contains the following PHP code:
Code:
<?
header(&quot;Expires: Mon, 26 Jul 1997 05:00:00 GMT&quot;);
header(&quot;Last-Modified: &quot; . gmdate(&quot;D, d M Y H:i:s&quot;) . &quot; GMT&quot;); 
header(&quot;Cache-Control: no-store, no-cache, must-revalidate&quot;);
header(&quot;Pragma: no-cache&quot;);
?>

This code disable page cacheing in most browsers and proxy servers. In any page that I do not want to be cached I include that file:

<?
include '/path/to/files/nocache.inc';
?>

once I use that include function, the code in that file will be included and 'parsed'.

Hope this helps :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top