Notice: Undefined variable: s_offline in /homepages/6/d168803796/htdocs/officetrio.com/o3/o3start.php on line 314
Learn PHP OfficeTrio: The Integrated ECommerce Solution OfficeTrio: The Integrated ECommerce Solution OfficeTrio: Features OfficeTrio: User Manual OfficeTrio: Testimonials OfficeTrio: The Demo is Offline! OfficeTrio: Order O3 Now

PHP

PHP Basics

PHP is a powerful language that's easy to learn and use. It's embedded in your web pages - i.e. you put your code directly into the web page, delimited by special tags. You use one of the following tags to indicate to your webserver that what's contained is a block of PHP code, which needs processing:

  • <php> ..followed by.. </php>
  • <?php> ..followed by.. </?php>
  • <?> ..followed by.. </?>

The webserver software that's running on your webhost responds to requests from browsers by sending the requested web page. If that page contains PHP commands, then before the page is sent, the bit in the special tags is processed by the PHP processor, it's the output of your PHP code that's displayed - not the code itself!

PHP's syntax is similar to the 'C' programming language - the standard compiled language that comes with Unix. It's very widely used, in fact most of Unix itself is written in C. (C now has an object-oriented derivative called 'C++' that's also very popular.)

A example PHP statement is:

 echo ("Hello World!\n");

Note that the statement consists of a function name ('echo' - prints text to the screen), followed by its parameters in round brackets. Strings are delimited by double quote marks '"'. The '\n' character means "New Line". The statement is terminated with a semi-colon ';'.

PHP has all the usual types, control structures, operators and functions that you'd expect to find in any general-purpose language. There are PHP functions to make most webmaster's jobs amazingly easy. PHP contains functions to access many different databases, it'll handle email and images, run files, manage cookies... It'll do just about everything you could need.

One particularly useful feature of PHP is that you can get a PHP file to run itself... This makes processing forms really convenient - as the form, and the code that checks it are all in the same file...

INFO:

PHP scripts ability to run themselves allow this sort of thing:

  1. The first time the form is called - all the variables (form fields) are blank...

    The code checks this and runs some code to display the form.

  2. Your customer fills in the form, then presses submit.

  3. Submit is set to call the same script using this code (The $PHP_SELF variable is built-in to PHP!):
    <form action="<? echo $PHP_SELF; ?>" method="post">

  4. The script now checks to see if the variables are set - they are...

    It can now check all the fields in the form.

    • If all the fields are OK it goes to the next page, or displays the next bit of code. (If it was a login page - it could display your user info for example).

    • If there are mistakes, however, the display code is run again, but mistakes in fields can now be shown up in red (for example).

    • Once submit is clicked again - the process repeats.
You'll see example of this method of form processing in many places on the 'net. You can achieve the same results with a Perl script, but it is easier in PHP.


Web pages with SSI in them (see the chapter on Perl) usually need to be given a .shtml extension (i.e. index.shtml) otherwise they are not processed. Similarly PHP files need to have a .php, php3, .php4, .phtml extension before they'll be processed... If you have PHP code in a .html file - it'll get sent to the browser directly - it won't look pretty!

INFO: The reason why you have to give special file extensions to dynamic web pages is this:

  • Normal .html files are just copied out by the webserver to the browser.
  • PHP files must be processed by the webserver and the PHP engine.
  • The PHP processing takes much more effort than the webserver's.

So, to avoid extra work - you tell the webserver which ones need the extra processing - by giving them a special extension.


PHP Resources

The first PHP documentation set to get is from PHP.net. They provide a downloadable documentation set which is pretty good!


Books (from Amazon.com)
>Programming PHP
by Rasmus Lerdorf, Kevin Tatroe
Co-authored by its creator, Programming PHP is a nitty-gritty guide to PHP development.
>PHP Pocket Reference
by Rasmus Lerdorf
This slim quick reference is a handy companion for all PHP developers. The author, Rasmus Lerdorf, is the creator of PHP, and PHP Pocket Reference is truly authoritative. It does not assume any prior knowledge and explains all the basics.
>PHP Cookbook
by David Sklar, Adam Trachtenberg
The PHP Cookbook is a collection of problems, solutions, and practical examples for PHP programmers. The book contains a unique and extensive collection of best practices for everyday PHP programming dilemmas.
>Professional PHP4 Web Design Solutions
by Luis Argerich, Alison Gianotto, Raj Dash, Matt Anton, Jon Stephens, Bryan Waters, Jo Henrick
This title shows web developers the versatility of PHP for large-scale web applications. It features case studies showing PHP use with output in HTML, XML, and WML. The PHP programming techniques are presented in such a manner that readers should be able to extrapolate the techniques (from both the theory and the case studies) for their own applications.
>PHP and MYSQL for Dummies
by Valade
This is an introductory level book that provides the essential information needed to enable users to build common Web database applications. The book is directed toward users who know HTML and have created static Web pages, but no prior experience with programming or database design or use is required
>Web Database Applications with PHP and MySQL
by Hugh E Williams, David Lane
Web Database Applications shows Web developers how to build rich Web database applications using two leading open-source technologies, PHP and MySQL. The authors also assume use of the Apache Web server, which is by far the most common PHP scenario. Both PHP and MySQL are introduced from scratch, although this is a fast-paced book best suited to at least intermediate developers.

Online Resources
PHP.net PHP's Home page!
PHPBuilder.com Been around for years. Big community. Loads of code, examples, tutorials etc...
Weberdev A general web-development site. Lots of articles and examples of PHP.
PHP at Resourceindex.com This is a generic index site, there are links to quite a few tutorials etc. You'll find my scripts here!..
HotScripts.com Have thousands of free PHP (and other) scripts...
ScriptZ.com Have loads of great free PHP (and other) scripts...
PHP Scripts Directory PHP Script Index More free PHP (and other) scripts...
ScriptSearch.com Loads of free and commercial scripts...



Tutorials

Contents

Free EBooks
Free Scripts

Introduction
What Can I Do With A Website?
Internet History
Introduction
Preparation
Website Builders

Webmaster's Tools
Tools Intro
HTML Editor
PHP IDEs
Graphics Resources
Telnet and FTP
Miscellaneous Tools

Web Design
Web Design
Domains
Keywords/Description
Logo/Graphics

Creating Web Pages
Setup
HTML
HTML Tips And Tricks
Home Page
Navigation
Other Pages

Webhosting and Unix
Webhosting
Telnet/Unix
More Unix
Website Upload
Analyse And Verify

Programming
Programming 1
Programming 2

PHP
PHP
PHP Scripts
PHP Hit Counter Script
PHP Download Tracking Script
PHP Navigation Script
PHP Affiliates Tracking Script
PHP Users Management
PHP Site Search Script

Perl
Perl
Perl Hit Counter Script
Perl Order Processing Script

Databases
Databases
SQL
Database Setup

ECommerce
ECommerce

Automation
Automating Order Processing
PayPal Automation
Email Automation
Installing Scripts

Security
Basic Security

Affiliates
Affiliates Programs

Managing Your Website
Website Management
Promotion/Advertising
Search Engines
Search Engine Optimisation



Powered By OfficeTrio