NEWS CATEGORIES:



NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
Home / News / Webmaster / Tips and Tricks

Tips and Tricks


A Simple PHP Template Example

The Usage of PHP Built-in Functions include() and require()

By Catalin Bocanu, Web News Editor

3rd of January 2008, 19:37 GMT

Adjust text size:


PHP LOGO
Enlarge picture
HTML templates are easy to design using a visual editing tool but when a website gains a certain level of complexity having a high number of web pages and links, the site maintenance activity becomes harder.
If you use a PHP template, a repeating code like a menu or a header which must be reused, could be introduced on all website pages with the help of a two PHP built in functions: include() and require().

These functions are able to insert the content of any type of file in a PHP file, but without being processed on server side. Practically, if you have a big web site and you add only a web page, the navigation menu links must be modified on every individual web page, when you deal only with simple HTML pages. In the case of PHP templates, where the menu is included as file in every page, you just have to edit a single file containing all links necessary for your website navigation.

A simple PHP template example, which uses the include() function is shown in the next code (you must save this code as index.php):

[CODE=0]
MyFirstPHPTemplate


This is the simple PHP template example

[CODE=1]

The file mymenu.php must contain the navigation links for your website. If we suppose that your website will contain three pages named index.php, news.php and contact.php, then the mymenu.php file could contain un unordered list which reflects the necessary links to the desired pages :

[CODE=0]
Home
News
Contact
[CODE=1]

The file index.php must be saved as news.php, respectively contact.php, because we decided that it is the base of our PHP template. All PHP files must be in the same directory. Now, you are ready to test this PHP example website and to notice that any new page you define, the only modification must be made inside mymenu.php file by adding a new link.

The include() and require() functions are identical excepting the modality of handling errors: both of them generate a warning message in case of an error, but require() function will return a fatal error. By using the require() function the control over the error source is more precisely.

TAGS:

PHP Template | PHP Tutorial | Free PHP Scripts | Server Side Includes | Free PHP Templates


Rating:
Good (3.0/5) 7 vote(s) so far    

Read by 1,647 user(s) | Add comment | Link to this article
Subscribe to news | Print article | Send to friend

© Copyright 2001-2008 Softpedia
Contact:

 

 

SEARCH THE NEWS ARCHIVE :




Today's News
| Yesterday's News | News Archive


MORE RELATED ARTICLES:


Tips to Improve Joomla Performance

How to Install phpMyAdmin on Windows

The World of PHP

Old PHP Scripts Compatibility with Actual Hosting Services

What Should You Choose, PHP or ASP ?

A Free Multilingual Real Estate Website

Free Visual Tool for PHP.ini Configuration on Windows

Free Hosting Services for WordPress Blogs

Forms To Go

Web Based Proxies

User opinions:

No user comments yet.
Be the first to express your opinion using the form below!

Share your opinion:

You are not logged on. Comments can still be added, but they will have to be approved before going live.
Log on to get your comments posted and visible instantly.
Your Name:
Your Email Address:
(will not be used for commercial purposes)
Your review/opinion:

 






SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   ENTER NEWS SITE   |   ENGLISH BOARD   |   ROMANIAN FORUM