ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

A Server Side Web Tutorial Series # 1 - An Introduction to PHP, An Open Source Server-side Scripting Language

Updated on April 6, 2014

PHP Utilized in Hundreds of Millions of Web Sites

Documentation of PHP is readily available through the XAMPP installation.
Documentation of PHP is readily available through the XAMPP installation.

What is PHP? What is it Good For?

PHP is yet another programming language but before you let a groan out let's talk about it a bit. I believe you will see the necessity of knowing something about if you anticipate doing some web development that PHP occupies a unique niche.

Another bright spot in the learning of PHP is that many of the programming constructs you will see demonstrated here you already know from other languages, be it C, C++, JavaScript, etc. Looping constructs such as if...else, if....else...if, for loops, while loops, do...while loops and switch statements will all be found in PHP. Operators such as arithmetic, conditional, and logical operators look very much like you will have seen in other programming languages. So that part of the learning curve curve will move quickly. Of the usual constructs and operator the thing which will be somewhat different is the syntax of handling arrays although the semantics and purpose of arrays is identical to that found in other languages.

Now, to the original caption heading questions: "What is PHP?" and "What is it good for?"

PHP as far as acronyms is concerned has a a somewhat checkered history. Some claim that it stands for "Personal Home Pages" while others claim that the letters came first and then the name was chosen. If that's true then PHP developers came up with "hypertext preprocessor". In any case, PHP is a powerful, server side programming language installed and used in millions of web sites. We'll look at its features in the next section.

Features of PHP

Although PHP can also be used as a general purpose programming language it is though of most as a web scripting language which is server-side based. Some of the major features of PHP include:

  • the ability to dynamically generate web page content
  • it can manipulate data in a data base. The popular option which is used in practice is to install PHP in conjunction with MySQL to create, modify, delete data in a MySQL repository.
  • PHP can provide data protection through encryption
  • PHP can interact with web "cookies"
  • it can act as an access control mechanchism
  • it can harvest form data entered by users and manipulate that data.

Advantages of Using PHP

The first advantage of using PHP is that it is open source and free. Free is always a good word when one talks about technology implementation. Free is only good if the product is good. Some of the other advantages of PHP are:

  • it is a cross-platform product. It runs on Windows, Linux, Mac OS X, UNIX
  • it is compatible with most web servers today (We will focus on its use with Apache.)
  • besides MySQL is can support other databases
  • its relatively easy to learn.

Administration of MySQL Databases is Often Handled by PHP

phpMyAdmin is a widely used PHP based way of administrating MySQL databases.
phpMyAdmin is a widely used PHP based way of administrating MySQL databases.

Some Prerequisites and Useful Links Before Starting

Some Basic Knowledge of HTML, CSS, and JavaScript

Some of the things you might want to consider before embarking on these tutorial is whether you have an adequate background to proceed. PHP can interact with HTML, CSS, and JavaScript. In fact PHP files can contain elements of these other languages as well as text. If you do not have a background in these or are just a little rusty and need some review you might consider look at some of my tutorials which I keep adding to from time to time. For HTML the series starts with "A Web Tutorial Series: Creating Your Own Presence on the World Wide Web - Introducing HTML 5". For CSS, it begins at " A Tutorial Series CSS for Beginners: Cascading Style Sheets - An Introduction" and for JavaScript, A Beginner JavaScript Tutorial Series: An Introduction to JavaScript - Identifying Basic Requirements.

An XAMPP Installation is Prefered for Windows

For the purpose of this tutorial we will be using an XAMPP installation as our webserver on our local host. For those following on LINUX or Mac OS based systems, appropriate packages are available for your operating systems. The reason for this is the simplicity of the installation process, the ease of administering it, and the fact that it also contains several useful products which are installed with it: MySQL, a useful database to experiment and possibly later implement with, FileZilla, a file transfer program, Mercury, a mail server product, and Tomcat, which is the open systems implementation for Java Servlet and Java Server Pages. Perl, PHP, and PHPMyAdmin are also included in the easily installed zip file. For more information, you might want to consult my XAMPP tutorials at "A Tutorial Series Testing Your Web Devlopment: Part I. Setting Up Your Own Local Web Server Using XAMPP". I will be adding to this series discussing some of the very few problems I encountered with it use.

The XAMPP Control Console

A snapshot of the XAMPP control console. XAMPP include support for Apache, Tomcat, Mercury, FileZilla, and MySQL. PHP, PHPMyAdmin and Perl are also included.
A snapshot of the XAMPP control console. XAMPP include support for Apache, Tomcat, Mercury, FileZilla, and MySQL. PHP, PHPMyAdmin and Perl are also included.

A Sanity Check: Saying "Hi, There!" in a PHP Script

At this point, we assume that you have successfully installed either XAMPP (or one of its variants for the other operating systems supported.) We are now ready to begin. A good text processing program can help spot errors and generally has features which help catch syntax errors. In the Windows environment there are many such programs available. Some are at a reasonable cost and they do have some "extras". As far as free products are concerned I generally use Notepad++ since wherever I happen to be consulting, it is either present of I can download it on the fly.

So let's start. The simple program will be just an echo of the statement, enclosed in beginning and ending php tags, as follows

<?php

echo 'Hi There!';

?>

In order to run this program you will need to save it in the htdocs subdirectory of the xampp directory with the file extension of php. The following snapshot shows two things: 1) how I coded the example, and 2) the file name extension must be php.

Another test you may want to perform is:

  1. Go to your XAMPP console. If you do not have it started as yet. Click on your shortcut (if created or from a command line enter the path to the control executable (e.g. c:/xampp/xampp-control.exe). When that screen displays you can check out various thing about PHP by clicking on phpinfo() in the left-hand navigation bar or by looking at the sample programs.

The PHP phpinfo() Method Accessed From XAMPP

This is a shnapshot of some of the information provided by phpinfo() which is part of the XAMPP package.
This is a shnapshot of some of the information provided by phpinfo() which is part of the XAMPP package.

Wrap Up and What's Next

In this tutorial we discussed the features and advantages of using the PHP product in server-side web development. We indicated that rather than installing php singly as a product, a better approach would be to install XAMPP for Windows (or its equivalent for Mac OS X, LINUX, UNIX, etc.

We looked at several feature of an XAMPP installation: phpinfo(). We created the very simple PHP program including only the PHP tags and a simple echo statement and launched it from a Chrome browser window after stating the three requirements: 1) the filetype must be php; 2) it be saved in the htdocs subdirectory (to keep it simple at this point in time), and 3) referred to in the browser as localhost/filename.

In the next tutorial, we move rather quickly through a number of items: comments, variables, and operators. With a reasonable understanding of their common use and some, even limited programming background we should be able to accomplish this in one session.

Please Rate This Tutorial on Clarity & Conciseness

Cast your vote for Did this tutorial prive "quick answers"?
working

This website uses cookies

As a user in the EEA, your approval is needed on a few things. To provide a better website experience, hubpages.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://corp.maven.io/privacy-policy

Show Details
Necessary
HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
LoginThis is necessary to sign in to the HubPages Service.
Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
AkismetThis is used to detect comment spam. (Privacy Policy)
HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
Features
Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
MavenThis supports the Maven widget and search functionality. (Privacy Policy)
Marketing
Google AdSenseThis is an ad network. (Privacy Policy)
Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
Index ExchangeThis is an ad network. (Privacy Policy)
SovrnThis is an ad network. (Privacy Policy)
Facebook AdsThis is an ad network. (Privacy Policy)
Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
AppNexusThis is an ad network. (Privacy Policy)
OpenxThis is an ad network. (Privacy Policy)
Rubicon ProjectThis is an ad network. (Privacy Policy)
TripleLiftThis is an ad network. (Privacy Policy)
Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
Statistics
Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)
ClickscoThis is a data management platform studying reader behavior (Privacy Policy)