What is PHP? – PHP Tutorial

What is PHP?

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.

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 here. We have outlined the sections we will be using and the order we will use them in for this tutorial below.

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.