What is PHP?

by

Self-referentially short for PHP: Hypertext Preprocessor, an open source, server-side, HTML embedded scripting language used to create dynamic Web pages.

PHP is an extremely popular and robust scripting language. Though it can be configured for other uses its primary function is as a server-side language for creating web pages. In this role it is used by millions of websites worldwide, across a wide variety of platforms and operating systems, to quickly and efficiently serve up dynamic web pages.

PHP development has been a phenomenal success. At its humble creation by Rasmus Lerdorf more than 15 years ago PHP stood for “Personal Home Page.” The modern PHP developer has changed the acronym to “Hypertext Preprocessor.” Regardless of what it is called it remains the premiere open source solution for creating powerful standards-compliant web sites.

How does PHP work?

To understand how PHP functions we must first understand how a web page works. Every web page is written as code and resides on a computer known as a web server. When an internet user points their browser to that specific page the page code is read and displayed through the browser window.

All standard web browsers perform that same task – they interpret HyperText Markup Language (HTML) code from a web server into a formatted and human-readable web page for the browser user. HTML source code is just plain text filled with tags and code markers. When viewed through a browser program that code becomes the web pages we see every day, filled with images, colors, and hyperlinks.

In order to accomplish this the web browser must download the entirety of the page code every single time the page is viewed. The resulting web page will always be the same as well, there is no way to, for example, have a greeting for Windows users that is different from the greeting for Mac users.

PHP development has given us the means to do this and so much more. It is called a Hypertext Preprocessor because when a browser requests the web page code the PHP interprets that HTML before passing it on. In this way the viewable web page can be changed depending on any number of variables, things like the user’s browser, operating system, the time of day, whether the user has visited the site previously, and all manner of other things.

Web applications of virtually any size can be built using PHP. The syntax for PHP is very straight forward, which is one of the reasons it is so popular.

Examples: This bit of PHP code will check and see if if a user is logged in or not.

<?php
function loggedIn(){
//Session logged is set if the user is logged in
//set it on 1 if the user has successfully logged in
//if it wasn't set create a login form
if(!$_SESSION['loggd']){
echo'<form action="checkLogin.php" method="post">
<p>
Username:<br>
<input type="text" name="username">
</p>
<p>
Password:<br>
<input type="password" name="username">
</p>
<p>
<input type="submit" name="submit" value="Log In">
</p>
</form>';
//if session is equal to 1, display
//Welcome, and whaterver their user name is
}else{
echo 'Welcome, '.$_SESSION['username'];
}
}
?>

What are the benefits of using PHP?

The benefits of using PHP are numerous. One of the biggest is that PHP is an open source language. It has been written and tested over the course of many years and has not been limited to a single PHP developer. This ensures both its continued development by enthusiastic programmers and its availability at little or no cost.

It is also extremely versatile. There is almost no modern operating system or hardware configuration unable to run PHP, allowing it to be used by nearly everyone. Many compatible addon modules have also been created to allow for functions the original core language does not include.

Compared to a static HTML web site PHP is much easier to maintain. As an example consider a site with 100 web pages, each one needing to have a company address and phone number in the footer. HTML requires this information to be included in the code of every page, so if that information ever changes all 100 pages must be updated and rewritten. With PHP every page could simply call the same small text file with the company information to include it in the footer. The information can be changed just once, in that single file, and will automatically be updated in any web page accessing it.

For this same reason web pages written with PHP are not as resource-intensive as HTML. The bulk of the page code is processed by the web server and not by the user’s computer. This results in quicker load times and more efficient processing. It allows a web page to execute database queries that can only be run on the web server as well, such as to access a membership list or spreadsheet of shopping habits.

What are some examples of PHP web applications?

The flexibility of PHP has also been used to create a number of excellent Content Management Systems, or CMS. A CMS is an application that allows simple and intuitive creation and maintenance of content, often web content. Popular CMS platforms such as WordPress, Joomla, Drupal, Magento and many others are written with PHP and allow users to easily create their own web sites featuring blogs, forums, image galleries, and other multimedia content. MediaWiki, the platform that powers the incredibly influential Wikipedia and its sister projects, is also written with PHP.

PHP holds a unique position among server-side scripting languages and there are many reasons for its incredible popularity as a means of building dynamic web sites. It is fast, efficient, and free to use. The huge community of developers makes it very stable and user-friendly. Sites using PHP are extremely easy to maintain, modify, and update. Basically it can do anything that HTML can do quicker and more efficiently. The internet of today would look very different were it not for the power of PHP.