Webmasters Tricks
*

My Tricks
Home Using "www2" Favicon Autodate Translation Tooltips Link Cloaking Track With 1 Pixel PHP Autodate SEO & Tables Screen Capture Website Scruffies Clever Subdomain Cloaking Trick PHP Includes Fancy Table Borders
My Tools
Private PLR Club Newbies School of Internet Marketing CheatKit Graphics Wizard CheatKit ListBuilder CheatKit Viral ListStorm Survey Convertor The Free Trial Machine ExitBlocker Cloak & Track Toolkit Forum Marketing Kit Scroller Control Newbies Starter Kit Ultimate Package Brander Affiliate PDF Brander Turbo Content SiteBuilder Content Rewriter Pro Grab That Sale! Web Protect Pro

Webmasters Cheat Kit - A Range Of Easy To Use Website ToolsThere are no "tricks" in my Private PLR Club - just the most outstanding value. Each month my Members get a ton of high-quality Private Label Rights products for a very low monthly subscription.

Click Here To See Everything You Get!

How To Use "PHP Includes"

Many less experienced webmasters (and webmistresses) are very nervous about using "techie" stuff such as the web programming language, "PHP". Relax! You don't need to learn such programming from scratch! You just need to find code snippets which other people have created - in most cases it's quite legal.

One such example is using "PHP Includes", which can save you a huge amount of time when you're building websites which keep on growing, or when you want to change the same web page element on many different pages.

Take the "My Tricks" index on the left of this page. Each time I add a new "trick" the link needs to be added to the index - and the index appears on every page of the site.

Do I need to change every page? If I did, the job would take longer and longer each time I added a new page.

But, by using a PHP include snippet, I need to change and upload just one file - and the changed content appears on every page of this site.

Here's how you can do it easily (but please read the "Important Note" lower down this page):

Step 1
Use your normal web authoring software to create a web page with all the content that you want to include on each page of your site. In my example, I just created a page with a table and links to each of my "tricks" pages.

Step 2
Go into the "source" or "code" view of the page you've created and strip out all the normal HTML page tags (marked in red below)

<html>
<head>
head content
</head>
<body>

This is the content you created for including on every page
</body>
</html>

Step 3
Save the page with a ".php" extension not an ".html" extension e.g. "menu.php". You can save it wherever you like - I usually save such files in a folder on my server called "includes". But for the sake of simplicity, I'll assume in this example that the "menu.php" file is saved in the same folder as the web pages it's going to be inserted into. I'll refer to this below as the "includes file".

Step 4
Now open up each page on which you want this content to appear and, in the "source" or "code" view of your web authoring software, go to the place where you want the content to appear and type in this PHP code snippet:

<?php
include("menu.php")
?>

Change the bit in red to the file name of your includes file. If you have put this file in a folder below the folder where your regular web pages are located, you'll need to put the link to the file something like this:

<?php
include("my-includes/menu.php")
?>

.. where the bit in red is the name of the folder where your includes files are stored - "my-includes" in the example above.

If you have trouble in the "code" view of seeing where exactly to put the code snippet, here's a tip that I use.. in the "normal" or "design" view in your web authoring software, put some marker text, such as "here". Highlight this text and switch to "code" view. Most web authoring software will show this marker text highlighted in the "code" view. Then you can simple delete this marker text and insert the code snippet.

*

And that's it! Once you've gone through the task of putting the PHP include code snippet on every page and you've uploaded those pages - plus, of course the includes file, you need never touch those pages again.

Whenever you want to change the content - as I'll be doing when I've finished writing up this "trick" - just open up your includes file, make the changes and upload the file to your server. All your web pages will then show the changed content.

Important Note:
Every web page which runs PHP code - e.g. the pages where you have inserted your PHP Include code - should have the extension ".php", not ".html" or ".htm". If you are creating new pages with the code snippet, that's not a problem.

But you don't want to start renaming all your existing pages, particularly if they are indexed by the search engines.

If this is the case, you can get round this problem by using a ".htaccess" file. You can see how to do this on this page:

http://php.about.com/od/advancedphp/p/html_php.htm

It might seem a little complicated, but it's not really.

What a great time saver! I hope you've found this useful.

Regards
Ian Traynor
Ian Traynor
Professional Webmaster

P.S. If you want to thank me for this "trick", here's a PayPal donations button. Click on it to pay me anything you like, using either your PayPal account or your credit card:

These "Webmasters Tricks" are presented without any guarantee that they will work on your website, on your computer or in your browser! As with any technology, you must test everything very carefully!

Ian Traynor is a professional webmaster and internet marketer. He owns the Webmasters CheatKit range of products, and produces the weekly "Marketing Update" newsletter. You can