What is PHP? - PHP Tutorial

What is PHP?

This tutorial assumes beginner knowledge of HTMLCSS, and JavaScript.

PHP is a widely used free and open-source language for creating servers. Recent surveys show that more than 16,000,000 Web sites use PHP as a server side scripting language.

Why, you ask? The short answer: it’s powerful, it’s easy to use, and it’s free. PHP can be used for the most demanding of applications, and delivers excellent performance even at high loads. Built-in database support means that you can begin creating data-driven applications immediately. The wide support means it is easy to host and find resources for.

Tools

In order to walk through the curriculum you will need to setup some tools on your computer. These tools are free.

XAMPP - Runs on Mac OS X, Windows, Linux
Simple to use web server for testing your PHP scripts on your local computer. 

Komodo Edit - Runs on Mac OS X, Windows, Linux 
Allows us to write code much more efficiently by highlighting the syntax we will discuss throughout the curriculum.

Chrome - Runs on Mac OS X, Windows, Linux 
Modern web browser that will allow us to preview and debug our content

This tutorial is recommended and maintained by Zend a company that develops the PHP language. It is located hereExternal Link. We have outlined the sections we will be using and the order we will use them in for this tutorial below.

Tutorial

Workshop 1

Down the Rabbit Hole
An introduction to PHP’s variables and operators.

Calling All Operators
The rest of the PHP operators (there are many), and simple form processing.

Looping The Loop
Basic control structures explained.

The Food Factor
Arrays, PHP array functions, and what it all means.

Workshop 2

Rank and File
Everything you’re ever likely to need to know about dealing with external files from a PHP script.

Functionally Yours
All about functions, arguments, passing by reference, globals and scope.

The Bear Necessities
A gentle introduction to object oriented programming in PHP 4 and PHP 5.

Databases and Other Animals – Part 1
All about connecting to a MySQL database from PHP, using the mysql or mysqli extensions.

SQLite My Fire! – Part 1
Introducing another database: SQLite.

Frequently Asked Questions

These questions are meant help you solve specific but common problems that may pop up when using this language. They are meant to be read after you have gone through the tutorial and begin actual development.

Many of these questions and answers are taken from the official php.net FAQ maintained by the developers of php. If you can't find the question(s) you are looking for on this page try searching through that page.

How can I pass a variable from Javascript to PHP?

Since Javascript is (usually) a client-side technology, and PHP is (usually) a server-side technology, and since HTTP is a "stateless" protocol, the two languages cannot directly share variables.

It is, however, possible to pass variables between the two. One way of accomplishing this is to generate Javascript code with PHP, and have the browser refresh itself, passing specific variables back to the PHP script. The example below shows precisely how to do this -- it allows PHP code to capture screen height and width, something that is normally only possible on the client side.

Refer to this url for an example of a php script that would accomplish this task.

How can I securely store data?

For a variety of reasons you may want to store a piece of information in a way that ensures no unauthorized access occurs. This might be a user's password or social security number. Simply putting the piece of information in a secured database is not enough. In order to use this you will need to use a hashing function which magically, using complex mathematics, turns your string into a random mix of characters. For any given string the resulting random mix of characters is always the same allowing you to know if two pieces of data are the same without actually knowing what they are.

We recommend using crypt() because for most cases this will accomplish what you need without complication of the problem. Using crypt() is as easy as passing in a string and getting a hashed string in return. You can then compare hashes to see if a hashed string is equal to another hashed string.

You will want to refer to the crypt() php.net manual for further description on how to use it along with code samples.

Supplementary Resources

In no particular order these external resources supplement the tutorial by providing shortcuts to commonly used information and further learning.

A Session In The Cookie Jar
Sessions and cookies – how to keep track of visitors to your site.

Sinfully Simple
An introduction to PHP’s easiest method for dealing with XML.

Bugging Out – Part 1
Basic error handling.

The Trashman Cometh – Part 1
A primer in basic security.

The Trashman Cometh – Part 2
Putting the pieces together – a first Web application.

No News is Good News
Creating a simple RSS news aggregator.

Last modified: December 31, 2013