Design Firm
Hudson Web Design Agency
We're Social!
Resources

Ease Your Website Design and Programming Process with PHP Includes

By: Jonathan Church at HPWebSolutions Website Design

Submitted on Mon, Jul 20th, 2009 4:57 am

This is the first part of a series of mini how-tos that will help you get websites to production quicker.

In this article I will talk about using PHP includes during development. Many times you will put together a website and the client will ask for some seemingly small change at the end of the process. If it is a change to the template of the website, that which appears on every page of the site, you will have to go into the code for every page to make the change if you have not used includes on the server side. If you have used includes, you'd only have to make the change in one file and it would effect every page of the site.

For example, say your client's logo is displayed at the very top of the page above an image displaying their catch phrase. After you've built their entire website, they decide they want the logo to be below the catch phrase. If the website is only one or two pages, not a big deal, just go in and change it on those two pages. If the web site is 10 or 20 pages, now you have to change a lot of webpages for a very simple request.

What you can do is use PHP to dynamically put the template design together whenever the page is requested by a web browser. To do this, create a file called header.php. Put into this file everything from your opening tag down through all code that forms the template before the actual body content begins. By "body content" I mean the content that changes on every page. HTML, CSS, and any javascript can be typed in just like an html file. Then create a file called footer.php and put into it all of the template code that comes after the body content.

Now that you have made these two files header.php and footer.php, create your index.php page. Do not leave an index.html page on the server at www.yourdomain.com/html because the .html version will be displayed instead of index.php (this is the server default). In index.php, declare your opening html tag and header information. After closing the head tag, on a new line write include $_SERVER['DOCUMENT_ROOT'].'/header.php';. Then put in your body content for the index page. After that, write in include $_SERVER['DOCUMENT_ROOT'].'/footer.php';. Open up www.mydomain.com in the browser and test it. If you did it properly, you should see the website you coded.

Do the same for all other pages on your website. Now any time you want to make a change to the site's template all you have to do is edit header.php or footer.php. You can save a lot of time by structuring your code this way. If you are strictly a designer and not a coder, whoever is coding the websites you create should be doing it this way.

About the Author

Jonathan Church
HPWebSolutions Website Design
I am a web developer for HPWebSolutions Website Design and Marketing. I have been programming and marketing websites since 1999. I specialize in PHP, javascript, XHTML/CSS, and database programming and online search marketing. I enjoy optimizing code for maximum efficiency, correctness, and throughput. I am both self-taught and have a formal CS education from Binghamton University in New York. I enjoy helping people who are new to programming and spend a lot of time on the web development help forums. I was born and raised in New York's beautiful Hudson Valley. You can visit my company website at http://www.hpwebsolutions.com.

Elite Firms

Premier Agency's

Top Design Firms

Directory Sponsors

Write for Us

Are you a creative genius? Do you want to share your gift with others and enjoy recognition as an industry leading author? Write for us and get your voice heard.

Premiere Agencies - Highly Recommended by DesignFirms
Quick Links
Site Sponsors
Recent Echos!

FEATURED WEB AND MOBILE AGENCY OF THE WEEK
Learn more about Hudson Integrated Web Agency and the design services they provide. Browse...

Submit Your Best Work to the DesignFirms Awards Program
Since 2003, we've been hand selecting only the very best in design out of thousands of submissions...

Web Award Winner: Axeela
The Official website for the singer Axeela. View more award winners and submit your design to see...

View the Top 100 Design Firms
Everyone has a list. However, DesignFirms feels that only real customers should be able to decide...

Popular Cities
Lounge Lizard Top Design Firm

©2003-2020 DesignFirms, All Rights Reserved.
A professional web design, mobile development and marketing company directory.

Directory | Get a Quote | Leads | Jobs | Reviews | Portfolios | Design Awards | Blogs | Articles | Echo | Advertise

Page Generated in 0.49 seconds