Screen Printing

TUTORIALS » PHP / MySQL » PHP essentials (guided tutorials)

Introduction to PHP

Imagine if you had to program an online store, a social portal, a news site, or any other large website whose pages change continually; and you can only use HTML. You would have to hire tens or hundreds of web programmers to update (or even redo) each page of your site in real time, 24/7... not very effective.

PHP is a server side language

HTML is a client side language, which means that each page is written—from top to bottom—by the programmer and stored in individual .html text files inside the server. When a client (each viewer) requests a certain page, this page is downloaded from the server as is. In other words, the server does not deal with any process other than sending a copy of the original .html file to the client. This way the client's computer is the one that interprets the code and displays a nice colored page on the screen.

PHP, on the other hand, is a server side language. Server side languages allow the programmer to perform an enormous amount of conditional and automated tasks inside the server before a processed page is even sent to the client. For instance, if you are developing a news website, you would only have to code a few templates and scripts, and store all your news information in a database. This way the server will process the data and automatically build a customized HTML page—on the fly—each time a client requests a new page; all according to the date, the news section the client is browsing, the user's preferences, etc.

This way, instead of you writing thousands of pages manually, the server writes each page—in real time—according to your instructions.

More on server side vs. client side here.

PHP is free!

Unlike other proprietary server side languages such as Microsoft's ASP and Adobe's ColdFusion—which can be very costly to implement and use—PHP is open source. This means it was developed and it is maintained by a bunch of geeks around the world who do it mainly for their love for computers, without expecting any monetary reward for their fine work.

Yes, PHP is free! (Thank you geeks)

PHP scripts are also written in plain text files

Just as in HTML, the PHP code is written in plain text files. Actually, you can combine plain HTML code and PHP code inside a single text file. The PHP part will be processed by the server while the HTML part will be sent as is. You will learn how to do this soon.

Main PHP requirements

There are three major requirements you have to comply if you want your server to process PHP code.
  1. Your server has to have PHP installed (most of today's web servers do).
  2. All your text files which include PHP code must have the .php extension. So, from now on, forget about the .html extension when working with PHP. Even if you are including a HTML part inside your text file, you must use the .php extension; otherwise the server won't process your script. If you are a Windows user, make sure all file extensions are being displayed.
  3. All your PHP code must be written within the <?php and ?> tags.
    Note: Although some servers will also let you use the <? and ?> tags instead of <?php and ?>, this use is discouraged due to potential compatibility issues.

Now, it is time to move on to the next tutorial and start writing your first PHP script; but first, make sure you have access to a PHP enabled web server. You can either sign in for a commercial server or setup your own computer to work as a locally available web server.

If you are interested on renting a very reliable—yet affordable—web server with PHP, I recommend you signing in for a 1&1 Web Hosting plan. Any of the available plans will do just fine, but I highly recommend starting with the Home or Business plan (make sure you sign up for a Linux hosting, they work better for web purposes).

Please follow into the next tutorial to start working with PHP.

Comments & Questions