- You are here:
- WebsiteTips Home
- Web Site Resources
- Markup, Code
- PHP
- PHP Tutorials
PHP
Section 2: Articles and Tutorials on PHP Programming
Within the PHP Articles and Tutorials section you'll find annotated links to PHP help - PHP programming tutorials, helpful PHP tutorials for beginning through advanced PHP programmers. You'll find PHP help for PHP basics, PHP programming tutorials for advanced experts, PHP image rotation tutorials and scripts, helpful tutorials on PHP includes, creating templates with PHP, tutorials on PHP login systems, PHP security, PHP and MySQL, Web site navigation with PHP, formmail and mail spam prevention, and more.
Know of some great PHP help, PHP programming tutorials, tips, tools, documentation, manuals, software, tools, Web sites, books, or other PHP resources? Recommendations are welcome and appreciated!
On this page:
- General PHP Programming Tutorials
- Tutorials on .htaccess and PHP
- Tutorials on Images and PHP
- Tutorials on Includes and PHP
- Tutorials on Login Systems, Password Protection with PHP Programming
- Tutorials on MySQL and PHP Programming
- Tutorials on Navigation and PHP
- Tutorials on Regular Expressions and PHP
- Tutorials on Security and PHP Programming
- Tutorials on Style Switchers with PHP
- Other PHP Programming Tutorials
Also within PHP:
- PHP Home (6 pages total)
- Section 1: PHP and PHP-Related Documentation and Manuals (1 page)
- Section 3: Discussion Lists, and Newsgroups on PHP Programming (1 page)
- Section 4: Sites, Other Resources, and Books on PHP Programming (1 page)
- Section 5: PHP Tools - PHP Editors, Modules and Add-ons, Support Applications, Template Engines, and More (1 page)
Books on PHP
Recommended by WebsiteTips.com
Read short reviews and find more book recommendations on Web site-related topics in our Recommended Books, Software section!
General PHP Programming Tutorials
Note that many of these tutorials include PHP scripts, many of which are provided as downloadable files.
- Classes and PHP
PHP Builder's Rod Kreisler provides a good tutorial explaining classes. [by Rod Kreisler, for PHP Builder.] - The Difference between PHP-CGI and PHP as an Apache Module
Short tutorial on the benefits of running PHP-CGI vs. the drawbacks. [Article/tutorial dated 09/2006, by produke, for .htaccess Forum.] - PHP 101
Introductory eight-part series for beginners to PHP, in easy-to-understand language with helpful examples. Covers the very basics, including PHP variables, fundamental concepts, Web forms, and more, such as PHP'sswitch-case()
statement - an alternative to theif-else()
family of conditional statements, thewhile()
,do-while()
,for()
loops; thearray()
,explode()
,implode()
,sort()
,rsort()
,file()
functions, and much more. [Article/tutorial dated 07/17/2004, by Vikram Vaswani, for Zend.] - The PHP Anthology Volume 1, Chapter 1 - PHP Basics
“This chapter provides a summary of all the essentials you need in order to get around quickly in PHP, from how to use the manual, to understanding PHP error messages, and how includes work. There are also some tips for writing portable code, and we'll take a look at some of the main PHP configuration pitfalls.” [Article/tutorial dated 12/19/2003, by Harry Fuecks, for SitePoint.] - PHP Coding Guidelines
Helpful tips cover editor settings, naming conventions, code layout, and general guidelines. Good insight and tips. [Article/tutorial dated 12/29/2003, by Paul Waring, for evolt.org.] - PHP for Designers
Helpful introduction to the world of PHP. Covers a few basics, such as syntax, commenting, variables, quoting and escaping, functions, ending lines, and execution. [Article/tutorial dated 03/31/2004, by Matt Mullenweg, for Digital Web.] - Programming: PHP
Very clear, easy to follow introductory tutorial series on learning PHP by University of Texas, Austin for its users. Covers environment variables, conditionals, reading form data, writing form data to a file, reading from a file, sending email, and resources to more on PHP. [Tutorial series part of the Learning to Publish section, by TeamWeb, UT (Univ. of Texas) Austin.] - Top 21 PHP programming mistakes - Part 1: Seven Textbook Mistakes
by Sterling Hughes, for Zend. This tutorial reviews the 7 top mistakes typically made using PHP and how to avoid them. [Tutorial dated 08/13/2000 by Sterling Hughes, for Zend.]
See also PHPWeb Sites, Other Resources, and Books on PHP Programming for links to Web sites, Web site sections, weblogs / blogs on PHP, and other resources and books on PHP.
Tutorials on .htaccess and PHP
The first couple of listings below explain parts of the .htaccess rules needed to parse HTML pages as PHP.
AddType
Directive
Explains theAddType
Directive used with enabling PHP for HTML pages. “TheAddType
directive maps the given filename extensions onto the specified content type. MIME-type is the MIME type to use for filenames containing extension. This mapping is added to any already in force, overriding any mappings that already exist for the same extension. This directive can be used to add mappings not listed in the MIME types file (see theTypesConfig
directive).” Visit the above link for much more. [Article/tutorial via Apache Module mod_mime, Apache 2.0 Documentation, Apache.org.]- .htaccess, MIME Types and Handlers
Explains MIME types and handlers for .htaccess in an easy-to-understand way, including theAddType
Directive, which is used within .htaccess or httpd.conf to enable parsing HTML pages as PHP. Very helpful information here. [Article/tutorial by WATS.ca.]
The listings below are tutorials or discussion forum threads on how to parse HTML pages as PHP, along with tips and troubleshooting advice.
- How to parse HTML pages as PHP
Short but helpful information here on the .htaccess rules needed to parse HTML pages as PHP. [Forum post dated 03/07/2007, by karthikeyanr23, for PHP-Editors.] - Parsing PHP on .html pages
Explains how to parse PHP on .html pages using .htaccess or using httpd.conf. [Article/tutorial dated 07/18/2005, by Zann Marketing.] - PHP and .htaccess
Several tutorials here: Multiple Custom PHP.ini, Switch PHP between running as a CGI and an Apache module,AddType
to run .htm as .php. [Article/tutorial dated 09/2006, by produke, for .htaccess Forum.] - PHP, HTML & .htaccess
Helpful forum discussion on adding the appropriate .htaccess rules to use PHP on Apache servers. Note September 2007: Although this forum thread is dated 2004, this information still applies. [Forum thread dated 08/10/2004, via PHP Server Side Scripting forum, Webmasterworld.]
For more on .htaccess, see also Behind the Scenes with Apache's .htaccess (via Brainstorms and Raves).
Tutorials on Images and PHP
- A Better Image Rotator
More features, such as individual link URLs, customALT
andTITLE
attributes for each image, and more. The pros and cons of this approach are explained, code examples are provided, and more. [Article/tutorial dated 08/10/2004, by Dan Benjamin, for A List Apart.] - Creating Dynamic Images with PHP
Simple instructions for creating images dynamically with a TTF font file and PHP. [Tutorial by Rasmus Lerdorf, for PHP Builder.]
Tutorials on Includes and PHP
In addition to the tutorials listed below specifically on PHP Includes, other tutorials listed on this page use PHP includes within their approaches, too, such as those listed within Tutorials on Navigation and PHP.
- Easy-peasy PHP: Includes, Switching and Compression
This introductory tutorial takes you through the steps of creating a very basic Web page with some dynamic content using PHP includes and switch conditionals for customized content and navigation, and then adding compression to reduce the file size on the server. Be sure to check the comments, too, as there are many helpful tips tossed in there. [Article/tutorial dated 03/09/2005, by Jim Amos, for Digital Web.] - Easy-peasy PHP 2: A Different Approach
A follow-up article to the first (noted above), proposing “a better, more robust and secure method for getting started with using PHP on your Web site.” [Article/tutorial dated 07/11/2005, by Jim Amos, for Digital Web.] - Including Files in PHP - Beginner Tutorial
Thorough, well done, easy-to-understand tutorial that covers the essentials of creating PHP includes. Section on the core PHP constructs - theinclude()
construct for including files,include_once()
construct,require()
construct,require_once()
construct. Section on understanding paths - use of the$_SERVER['DOCUMENT_ROOT']
superglobal, using shortcuts or working directory paths. Section on smart development - command line and web interface applications. Sections on permissions on included files, PHP include file security, and notes on open base directory (open_basedir
) and safe mode. [Article/tutorial dated 04/05/2005, by php freaks.] - PHP Includes (for people who don't know PHP)
Easy to understand instructions about the basics of PHP includes, includinginclude()
syntax, a note on server paths, a sample implementation, and more. Good article for those who'd like to use PHP includes without the need for a lot of programming skill. [Article/tutorial dated 11/22/2005, by Rollie Hawk, for AllYourTech.com.] - PHP
require()
vs.include()
Short but insightful article and the difference in the uses for PHPrequire()
vs.include()
, along with simple examples. [Article/tutorial dated 11/11/2004, by Nazim Rahman, Self Improvement.] - Templating with PHP
Use simple PHP includes to create convenient and easy-to-manage templates for your Web site. Covers various approaches, such as pulling the template into your content, pulling your content into the template, or pulling both content and templating into and single file. Gives the basics about how to chunk it all out. Easy to follow tutorial. [Article/tutorial dated 06/29/2005, by Rollie Hawk, for AllYourTech.com.] - Where Are Your PHP Includes
Helpful security tips about where not to place your PHP include files, naming conventions, and why it matters so much. [Article/tutorial dated 03/24/2005, by Chris Shiflett, The PHP Blog.]
Tutorials on Login Systems, Password Protection with PHP Programming
- Apache HTTP Authentication with PHP
by Kevin Yank, webmasterbase.com. Learn how to create password protection to one page or an entire site with PHP. [Tutorial dated 11/01/2000, by Kevin Yank, for SitePoint (previously for WebmasterBase).] - PHP Login System with Admin Features
A popular tutorial and script at evolt.org that provides a feature-packed approach to a PHP login system for Web sites. [Tutorial dated 09/22/2004, by JP, for evolt.org.]
Tutorials on MySQL and PHP Programming
- Build Your Own Database Driven Website Using PHP & MySQL
Extensive excerpts from the book of the same name by Kevin Yank, published by SitePoint Pty, Ltd. A hands-on learning guide and highly recommended. Similar to the mysql.com below. [Tutorial dated 01/03/2002, by Kevin Yank, for Database Journal (previously for WDVL).] - Building a Database-Driven Web Site Using PHP and MySQL
by Kevin Yank of SitePoint.com for mySQL.com. A 10-part, detailed series. Well done, thorough. [Tutorial by Kevin Yank, for mySQL.com Developer Zone.] - Give me back my MySQL Command Line!
Tutorial on how to get rid of the Web-Based mySQL command line using PHP programming, handling queries, displaying result sets, then putting it all together. [Tutorial dated 11/21/2001 by Kevin Yank, Sitepoint.com] - How to Count Clicks in your Website
Peter Van Dijck, Evolt.org. Introductory tutorial for PHP and mySQL programming with easy to understand instructions. [Tutorial dated 02/02/2000, by Peter Van Dijck, for evolt.org.] - Multiple Pages With PHP
How to split up page results in a mySQL database (such as with next, previous links), defining variables, doing the math calculation, displaying the results, making the links. [Tutorial dated 12/29/2001, by Jester uk for evolt.org.]
Tutorials on Navigation and PHP
- Breadcrumbs for PHP Lovers
Written by Jakob for Evolt.org, learn how to make breadcrumb navigation with PHP. Comments and tips from readers here, too. Evolt.org has tutorials on breadcrumbs with ASP and others, too. [Tutorial dated 12/30/2000, by jstetser, for evolt.org.] - Keeping Navigation Current With PHP
How to use PHP includes to set up navigation to know which page the user is viewing and adjust the current-page indicator appropriately. For example, you can set up one global navigation PHP include file, using PHP to add a class or ID for the current page so that the current page will have an arrow bullet and no hyperlink, for example. Excellent tutorial, and this approach works well. Editor note April 2006: WebsiteTips.com's navigation is loosely based on the approach in this tutorial to easily allow current-page indicators. [By Jason Pearce for A List Apart, 11-07-2003.] - User-friendly Contextual Navigation with Simple PHP Includes
Usability experts continue to tell us not to have a live hyperlink pointing to the current page, as it can be confusing for visitors. With some basic, simple-to-use PHP and one PHP include file, you can customize your navigation so that the current page does not have a live hyperlink to itself. In addition, you can manage your entire site's navigation from that one include file, making your site's navigation management convenient, efficient, and easy to maintain. This short tutorial gives step-by-step instructions with code samples on how to create this type of navigation with a couple of short snippets of PHP code, clean and lean HTML markup, and one PHP include file for your entire site. [Article/tutorial dated 09/27/2006, by Shirley Kaiser, SKDesigns (WebsiteTips.com's owner, editor), for Brainstorms and Raves.]
Tutorials on Regular Expressions and PHP Programming
In addition to the tutorials below specifically related to using regular expressions with PHP, see also WebsiteTips.com's Web Resources Regular Expressions section.
- Learning to Use Regular Expressions by Example
Detailed tutorial that first explains the basics of regular expressions and then how regex works with PHP. Well done, easy to understand and follow. Written for PHP3 but can apply to newer versions, too. “straight-out introduction to the syntax and a step-by-step on building regular expressions to validate money and e-mail address strings. I just hope it manages to clear the fog around the subject for all you fellow programmers.” [Article/tutorial dated 10/30/2000, by Dario F. Gomes, for PHP Builder.] - PHP and Regular Expressions 101
Very basic introduction to PHP and regex. [Article/tutorial dated 05/31/2007, by Mitchell Harper, for PHP Builder.] - PHP Manual: Functions: Regular Expressions Functions (Perl-Compatible)
Introduction to PHP regex functions, configuration and installation information, table of predefined constants, and table of contents also includes links to more on each of these:- Pattern Modifiers - Describes possible modifiers in regex patterns
- Pattern Syntax - Describes PCRE regex syntax
preg_grep
- Return array entries that match the patternpreg_last_error
- Returns the error code of the last PCRE regex executionpreg_match_all
- Perform a global regular expression matchpreg_match
- Perform a regular expression matchpreg_quote
- Quote regular expression characterspreg_replace_callback
- Perform a regular expression search and replace using a callbackpreg_replace
- Perform a regular expression search and replacepreg_split
- Split string by a regular expression
- PHP tip: How to Strip Punctuation Characters from a Web Page
Incredibly helpful detail and explanations to strip only specific punctuation, whitespace, or to strip far more from a web page using PHP. “When processing text for a search engine or analysis tool, code needs to strip out punctuation, formatting, spacing, and control characters to reveal indexable text. In international text there are hundreds of these characters, and some should be removed in one context, but not in another. This tip shows how.” [Article/tutorial dated 09/15/2007, by Nadeau Software.] - Regular Expressions Tutorial
Compilation of snippets, notes on regex and PHP from several sites. [Article/tutorial by Jim Stitzel, Weblog Tools Collection.]
Related within Web Resources:
Tutorials on Security and PHP Programming
- PHP Formmail Spam Prevention
How to use a key and email value pair to keep your email address out of the html page within your PHP forms. Small fee to access tutorial. [Article/tutorial dated 08/25/2006, by Sheri German, for Community MX.] - Preventing spam when using PHP's mail function
Article/tutorial on how to make your PHP mail form more secure, including showing some of the common exploits, changing your script's name, checking for valid email, checking for suspicious strings, and more. As the introduction states, “Insecure PHP scripts have provided great opportunities for spammers to abuse others' resources to send out their spam. In particular, it's themail()
function that can be abused. I myself was the target a few months ago when I noticed spam being sent from an old form on my server that I'd forgotten about. This month's article looks at techniques that can be used to harden your mail form, and reduce the chances of it being misused.” [Article/tutorial dated 04/12/2006, by Ian Gilfillan, for PHP Builder.] - Top 7 PHP Security Blunders
Articles details many of the common PHP programming mistakes that can result in security holes by showing what not to do, and how each particular flaw can be exploited. [Article/tutorial dated 12/21/2005, by Pax Dickinson, for SitePoint.com.]
Tutorials on Style Switchers with PHP Programming
- Build a PHP Switcher
Tutorial with PHP programming code snippets, CSS, and instructions for creating a PHP style switcher. [Article/tutorial dated 10/13/2002, by Chris Clark, for A List Apart.] - Build Your Own PHP Style Sheet Switcher
A simple approach for a style switcher using PHP programming. Instructions and scripting included. This one allows for two different style sheets. Easy, includes cookies to remember the styles from page to page. Good comments and discussion there, too. [Article/tutorial dated 08/23/2006, by Roger Johansson, 456 Berea Street.] - PHP Style Changer Experiment
[Article/tutorial dated 09/01/2006, by Mike Cherim, for Beast-Blog.com.] - Stuff and Nonsense: Strategies for CSS Switching
Helpful tutorial, including the markup and scripts, for adding a style switching feature to your site using either JavaScript and CSS or PHP programming code and CSS. This tutorial is an excerpt from chapter 8 of Professional CSS, by Christopher Schmitt, Mark Trammell, Ethan Marcotte, Todd Dominey, Dunstan Orchard. [Tutorial is an excerpt from chapter 8 of Professional CSS, by Christopher Schmitt, Mark Trammell, Ethan Marcotte, Todd Dominey, Dunstan Orchard. Via Digital Web.]
See also:
Other PHP Programming Tutorials
- 100% Apache-Compliant REQUEST_URI for IIS and Windows!
“REQUEST_URI
for Windows is a must-install for absolutely anyone that uses IIS & PHP, no matter what software you run. It's free, it's one-hundred percent compatible with Apache's ownREQUEST_URI
, and best of all, it's guaranteed to work no matter what.REQUEST_URI
for Windows gets whatever the user entered into the address bar - period. Nothing more, nothing less. And of course, you never have to modify a single script to make them work, this does all the work for you.” [Article/tutorial dated 11/17/2006, by The Neosmart Files. Hat tip: Sally Nordquist via Wise-Women Discussion List.] - Apache and IIS
$_SERVER
Superglobal Comparison
Handy, helpful chart comparing$_SERVER
superglobal arrays on Apache vs. IIS servers. Those in bold work on all the platforms tested. “On this page, you will find a table of the keys that are defined in PHP's$_SERVER
superglobal array running on Apache and IIS servers. The purpose of this table is to allow PHP developers an insight of what to expect if they must migrate from one platform to another.” [Article/tutorial by Justin Koivisto, ZCE. Hat tip: Sally Nordquist via Wise-Women Discussion List.] - Different Text Based on Date (PHP)
Very simple script and instructions to display different text depending on the date. Works fine, easy to implement. Editor note April 2006: WebsiteTips.com uses this kind of approach to display the “New!” icons until a certain date, after which the icon no longer appears on the page. This type of approach is also used at this site to display specific text before a certain date and other text after that date. This simple scripting is a great help with keeping content fresh automatically. [Article/tutorial dated 07/13/2005, Zann Marketing Pty Ltd. Developer Blog.] - Displaying Page Load Times with PHP
Wondering how long one of your Web pages actually takes to load? Want to check your page load times for any reason? Here's a simple tutorial and script to do just that, and it works well. Editor note April 2006: WebsiteTips.com uses this for testing page load times, so I can vouch for it working well. (If it's in use when you read this, you might see it in action at the very bottom of each page in a pale light gray color). [Article/tutorial dated 06/21/2005, by Darren W. Hedlund, for Developer Tutorials.] - Make Your Site Mobile-Friendly in Two Minutes
Just because you use valid markup and an approach that separates content from presentation as much as possible still doesn't mean your site will work well on mobile devices. Mike's tutorial shows you how to use a little PHP to filter your site for mobile devices without needing to do a thing to your pages. This approach mirrors your site for mobile devices using a PHP global prepend, PHP global append, and activated within your .htaccess file. Mike provides screenshots of his own site and quite a few popular sites before and after, too - the page rendering is dramatically improved and the pages load incredibly faster, too. Well worth checking out. [Article/tutorial dated 07/19/2005, by Mike Davidson, Mike Industries.] - Manage Your Content With PHP
This tutorials gives step-by-stop instructions on how to build a simple, template-driven site that separates style, content, and structure. Included are instructions on creating a cross-browser stylesheet switcher that remembers the user's preferences, covers a bit on php variables, cookies,if
statements, and including pages withrequire_once
. [Article/tutorial dated 08/09/2002, by Christopher Robbins, for A List Apart.] - PHP and Anacom
by Michael Reynolds, PHP Builder. Learn how to handle online shopping with Anacom and PHP programming code with this tutorial. Also discusses using Curl for security. [Tutorial by Michael Reynolds PHP Builder.] - PHP, Gzip and htaccess
Use theauto_prepend_file
andauto_append_file
commands in your .htaccess file (Apache servers) along with PHP'sob_start("ob_gzhandler")
andob_flush();
to compress your Web site files without needing to add any PHP code to your files. Slick! See also PHP Manual:ob_gzhandler
for more onob_gzhandler
with helpful comments and code snippets from others, and note thatob_gzhandler
requires zlib. [Article/tutorial dated 05/24/2004, by Dave Child, ILoveJackDaniels.com weblog/blog.] - Search Engine Friendly URLs with PHP and Apache
Short but helpful article on changing dynamic URL syntax, such as question marks and other query strings, into more search engine friendly URLs with human readable URLs. You can download the PHP programming code script and files needed to set it up for your server, too. [Article/tutorial dated 08/20/2001, by Garrett Coakley, for evolt.org.] - Setting up Server Mappings in HomeSite
by Christopher Bradford, Macromedia. Read how to set up HomeSite with your local computer to view pages with server-side processing, such as SSI, ColdFusion, PHP, ASP. [Tutorial by Christopher Bradford, for Macromedia.] - Smarter Image Hotlinking Prevention
Tutorial shows how to use PHP and Apachemod_rewrite
to disallow embedding and allow linking while automatically creating gallery pages for those who directly linker to your images (also known as “hotlinkers”). [Article/tutorial dated 07/13/2004, by Thomas Scott, for A List Apart.] - Time Sensitive CSS
Clever use of PHP with CSS to use a specific CSS file based on the current month. “To start, I wanted to show how inclusion of various CSS files could be used to change aspects of a site design. I made a very rudimentary example that queries the server to get the date, and returns a CSS file via import based on the current month. There is one basic stylesheet, and twelve possible imported files. The actual example is nothing fancy, just a proof of concept.” There's also a CSS-based clock demo. Fascinating ideas here. [Article/tutorial dated 02/09/2006, by Nathan Smith, SonSpring.] - When Browsers Suck: PHP to the Rescue!
by Kevin Yank. Short tutorial that provides instructions for PHP code to replace lengthy JavaScript browser sniffers. [Tutorial dated 11/21/2001 by Kevin Yank, SitePoint.com.] - Writing more HTML-friendly PHP
Covers helpful basics for alternative syntax for control structures in PHP programming code - instead of enclosing everything in braces, this tutorial shows how to use ending condition checks with colons and finish things up withendif
. The result is cleaner, leaner code, and easier to read, too. Easy to understand tutorial with practical examples. [Article/tutorial dated 12/16/2005, by Rollie Hawk, for AllYourTech.com.]
See also PHP Web Sites, Other Resources, and Books on PHP for links to Web sites, Web site sections, weblogs / blogs on PHP programming, and other resources and books on PHP.
Sponsored Links: