Overview
KB
Learn PHP
PHP techniques
PHP basics
PHP Tutorial
PHP History
Command Line PHP
PHP Syntax
PHP Variables
PHP Superglobals
PHP Strings

PHP Tutorial

Web Application Development using PHP

This PHP tutorial provides a brief introduction to all of the fundamentals of programming with PHP. Most of these ideas can be neatly filed away under set categories. But there are several, smaller topics that are part of a more generic "Web application development with PHP" category:
  • Sending Email using PHP
  • HTTP Headers and PHP
  • Defining Your Own Functions in PHP
  • Working with Dates and Times in PHP
  • Improving Script and Site Performance
The first of these subjects—sending email using PHP—is self-explanatory and surprisingly easy, assuming that you have a valid email server set up already. For sending basic emails, all that is required is the mail() function. The second subject—HTTP headers and PHP—comes into play for a myriad of reasons, the most common of which is redirecting the user from one page to another. HTTP headers can also be used for sending files to the user (i.e., initiating a download), indicating to the browser what kind of content it's about to receive (e.g., XML), and more. Up next is a tutorial on defining and using your own functions in PHP. This is a simple enough concept, and very common in any Web application. Finally, the Web application development section shows you how to work with dates and times in PHP. PHP does not have a date or time data structure, but there are many functions for creating and manipulating dates and times. Finally, the Web application development section discusses ways to improve script and site performance. Doing so may involve tweaking your programming style, getting more out of a database, or using a profiler.

PHP State Management Techniques

HTML is a stateless technology, therefore a Web site, as a series of HTML pages, is also stateless. This means that each interaction between the user (i.e., the Web browser) and the server is a separate interaction, with no relationship to any other interactions. When a user is viewing http://www.nusphere.com, then clicks on a link to go to http://www.nusphere.com/download.php.ide.htm, those are two separate and unrelated occurrences. This all might sound strange for unseasoned Web developers but it's important to understand. In order to provide to the end user a seamless interaction, like the ability to log into and access areas of a site, you must workaround the stateless environment. PHP provides two different state management techniques for overcoming the problems inherent in the stateless Web. The first of these is the cookie. A cookie is a bit of information sent by a server to the Web browser, where it resides. When the Web browser goes to any subsequent page in that same domain, it provides to the server access to this same cookie. It's a simple and easy-to-implement option. Cookies, though, are limited as to how much information they can store and there are security implications involved. The second PHP state management technique is the session. A session stores all of the data on the server. For this reason, sessions can be more versatile and secure than cookies. The biggest potential problem with sessions is that they rely upon a session ID: an identifier that points to each unique set of session data. This session ID must be accessible on each page, either by passing it from page to page (which has its own security concerns) or by storing it in a cookie.

Database Interactions with PHP

PhpED's DB Client tab
Part of the success of the PHP programming language is how easily it interacts with database applications, in particular, open source ones such as MySQL, SQLite, and PostgreSQL. A database application (which is the proper name for the software) manages a database, which contains one or more—often-related—tables. The application manages all of the relevant permissions, has its own functions, and protects the integrity of the data stored therein. PHP is used as an interface to the database application, normally either sending new or updated data to the database or retrieving existing data from it. Database interactions with PHP are not complicated, thanks to PHP's support for them, but require knowledge of tangential topics. Primarily this means having a basic understanding of the database application's permissions system and learning SQL. SQL is the standardized language used to interact with almost every database application. Its syntax is simple but it can be used for impressively complex queries. Since database interactions with PHP are a standard aspect of many Web applications, using a development tool that can also facilitate these interactions is a great asset. Such a feature is lacking from almost every text editor, but can be found in better IDE's. The figure at right shows how you can view, navigate, and interact with databases directly in NuSphere™ PhpED.

Article continues:  <<previous page  next page>>

 Download NuSphere PHP IDE

Download a free trial of the fast PHP EDitor and robust Integrated Development Environment for PHP.

 Buy NuSphere PhpED® now

Best PHP Editor and complete PHP IDE.
NuSphere PhpED 20.0 is available from our online store front.

 Special Team4 Offer

Get 4 copies of PhpED for the price of 3!

Optimum solution for development teams.
PhpED 20.0 Team4
Need more than 4 licenses? Contact Us for more quantity discounts, please use "Ordering/Payment issue" subject on the form.
"To be honest its bloody awesome, I have looked at loads of PHP editors and this is THE only one that actual works straight out of the box!!! Brilliant, well done."
Andrew Breward,
Director of Technology
caboodal.com