PHP, which stands for "PHP: Hypertext Preprocessor", is a widely-used Open Source general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. Its syntax draws upon C, Java, and Perl, and is easy to learn. The main goal of the language is to allow web developers to write dynamically generated web pages quickly, but you can do much more with PHP.
The PHP Hypertext Preprocessor is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications. So PHP is about connecting an HTML page to a server-side program or database.
PHP is a Web application server. At its heart is a database-to-Web gateway, meaning that it allows you to easily display records from a database on an HTML page.
A sample of what this means is a fake checkbook manager at my own server. (Use the username harry and a password of potter.)
You should note carefully that the tags that you see which look like <?php or ?> are PHP tags. These tags are recognized by the PHP server and are processed by that server as it constructs an HTML page to send back to the browser.
The code that is between <?php and ?> is PHP programming code.
Here is the source code for the main page (checkbook.php):
<?php
require "loginAndLogout.php";
require "config.php";
$mysqli = new mysqli(DBSERVER, DBUSER, DBPWD, DBNAME);
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Home Checkbook</title>
<link rel="stylesheet" type="text/css" href="checkbook.css" />
<script type="text/javascript" src="includes/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(':submit').css("cursor", "pointer");
});
function logoff()
{
var returnValue = confirm("Do you really want to log off?");
if (returnValue == true)
{
document.getElementById("autoLogoff").value = "1";
return true;
}
else
{
return false;
}
}
</script>
</head>
<body>
<div id="checkDiv">
<h1>Home Checkbook</h1>
<br />
<form action="addtrans.php" id="addtransForm" name="addtransForm" method="post">
<input type="submit" value="Add a Transaction">
</form>
<form action="loginAndLogout.php" id="logoutForm" name="logoutForm" class="extraLeftSpace" method="post"
onsubmit="return logoff();">
<input type="hidden" name="autoLogoff" id="autoLogoff" value="0">
<input type="submit" value="Log off">
</form>
<br />
<br />
<table id="mainTable">
<tr>
<th> Date</th>
<th> Amount</th>
<th> Description</th>
<th> </th>
<th> </th>
</tr>
<?php
$query = "SELECT * FROM Transaction ORDER BY TransDate DESC, Description";
$result = $mysqli->query($query);
$row = $result->fetch_assoc();
while ($row !== null)
{
$rowId = $row["ID"];
$transDate = $row["TransDate"];
$amount = $row["Amount"];
$descr = $row["Description"];
printf('<tr>
<td class="numeric">%s</td>
<td class="numeric">$%01.2f</td>
<td>%s</td>
<td>
<form action="edittrans.php" method="post">
<input type="hidden" name="rowID" value="%d" />
<input type="submit" value="Edit" />
</form>
</td>
<td>
<form action="deletetrans.php" method="post">
<input type="hidden" name="rowID" value="%d" />
<input type="submit" value="Delete" />
</form>
</td>
</tr>',
date("m/d/Y", strtotime($transDate)),
$amount,
$descr,
$rowId,
$rowId);
$row = $result->fetch_assoc();
} //end while()
?>
</table>
<br />
<form action="addtrans.php" id="addtransForm" name="addtransForm" method="post">
<input type="submit" value="Add a Transaction">
</form>
<br />
</div>
</body>
</html>
As we go along through the semester, you will discover what this page is doing. For now, simply note that the code between the
<?phpand
?>tags is doing these steps:
The most recent update to PHP as of November 2020 is version 8.
I will teach PHP version 5 in this class.
PHP has recently gone through several version updates, but version 5 is still the most commonly-used version. I expect that this situation will slowly change. In a few semesters I will probably be teaching PHP version 8.
The change from PHP version 4 to version 5 was major. But since I am teaching PHP version 5, we don't need to go into the differences.
The change from PHP version 5 to version 6 was very minor. I don't even teach about those parts of PHP which were affected by version 6, so we will not need to go into those differences, either.
The change from PHP version 6 to version 7 was also very minor.
But PHP version 8 has introduced some major differences from the previously-latest version, which was version 7.4.
On the other hand, if you will pay attention to what I teach about PHP version 5 this semester, you will be prepared for the eventual world in which PHP version 8 dominates. I will teach you good, standard PHP coding techniques which will not be a problem when you run your PHP pages under version 8.
But just in case you are interested in what has changed in version 8, the PHP.net site has a good and extensive listing of the changes, in their Migrating from PHP7.4.x to PHP 8.0.x page. I am going to list some of the most major and important changes below.
The following diagram will give you a rough idea of how the information requests and responses flow among the browser, the Web Server, the PHP Server, the database server, and the SMTP (e-mail) server when you display a PHP page in your browser.
Please note these points about the above explanation:
You do not need to set up any PHP installation to work the assignments in this course. The information on this page is for your possible future reference, only.
The Web server where you will be uploading your assignment pages has PHP running on it already.
If you are going to host your PHP with an outside Web provider rather than on your own server, you need to get information from the Internet Service Provider (ISP) about:
But please note that you are *not* required to get a hosted web site in order to take this class! You will be uploading your assignment pages to a school server which has PHP running on it.
The ISP that I use for my www.jimlink.net site is running PHP 8 on their servers. (Actually, I can run just about any previous verion, also. We are going to use PHP 5 for this class.) The functions that I mention above are turned on. If you want a reliable ISP with great customer service, consider using GoDaddy as your ISP.
Later in this course, I will tell you how to set up the database datasource names.
You can install PHP on your local computer with the XAMPP system.
But please note that you are *not* required to install PHP locally in order to take this class! You will be uploading your assignment pages to a school server which has PHP running on it.
If you decide to run a local PHP installation, you can follow the instructions in the book, or you can use the following instructions, which are pretty much like the instructions in the book, starting with page 8. I have added some hints of my own.
http://localhostand you should see the XAMPP for Windows (assuming you did a Windows installation!) "Welcome" screen. You can also click the "Status" navigation link in this "Welcome" screen to see if everything is running. It is okay, and expected for this "Lite" version of the installation, for the "Perl with mod_perl" and "Apache::ASP" indicators to be red.
http://localhostinto your browser's address field, you may be required to enter the username and password that you set. This is a good thing.
You can also install PHP on your local computer using the WAMP system.
But please note that you are *not* required to install PHP locally in order to take this class! You will be uploading your assignment pages to a school server which has PHP running on it.
If you decide to run a local PHP installation, you can follow these instructions:
http://localhost