Dec 27, 2006

The Best Snippet of Code Ever

Adsense Tip: The best little snippet of code I’ve discovered for to build better pages. BEGINNERS GUIDE TO PHP INCLUDES

Have you drudgingly designed a large site, published it and sat back with a sigh of relief that it’s finally done? Then later that day or week realized, oh no, it’s gotta change and had to go back through EVERY PAGE of your website to change it? I think as beginning designers, we’ve all gone through this. open copy paste save close. Its Mindnumbing, and we only have ourselves to blame because we know there’s a RIGHT way to design the site in the first place.

That right way is with PHP includes.

<?php include ('file.html'); ?>

Thats it folks! Thats all it takes to make global changes to an entire website with just one file.

ANYTHING that you think may change, ESPECIALLY your adsense code should be written in html and brought onto your page with the code above.

Navigation systems are especially important to bring in with php.
Footers with stat code is important to include with php.

You can include as much or as little as you want with php, and its REALLY easy.

There are some things you need to know to get it working correctly.

Start out by designing one page in html exactly how you want your site to look.

Get your layout, optimization, cascading style sheets, images and navigation in order. Then, save the file with the extension as .php instead of .html Go back in and copy the elements you think you may eventually need to change. Paste them into a new html file. Make sure to leave out the html, title, head and body tags OUT of this html file. you only need straight code.

When the pieces are put back together in your browser, it looks like one straight page of html code. It will read the external html code where it is on the page. If you’ve designed that portion with styles, you dont even have to include the link to the styles, it will read it from your original .php header code.

Now go back to where you copied the html from and put this php include code in its place.

<?php include ('file.html'); ?>

Make sure to use the right filename. So if you’re adding your navigation bar, you can use something like <?php include ('navbar.html'); ?> If you’re site will include subfolders, you might want to use absolute urls for your include code. so it will look like this:

<?php include ('http://yoursite.com/navbar.html'); ?>

All of your pages will be .php - and all of your code that you will want to make quick changes to will be .html

This is so handy for testing adsense colors, placement, sizes and styles.

If the includes dont show up, or you get lines of code on your page showing a mysql error, something with your php code is incorrect. If you’ve done this all correctly and find that it’s not working when published, you may want to try one last thing before contacting your web host.

Create a file called php.ini with the following code only:
register_globals = On

Upload this file to your server and see if it works now.