PHP Introduction



index
Disabled back button Next Section
printable version

Section 0: Module Objectives or Competencies
Course Objective or Competency
The student will be able to write basic PHP applications in order to connect to and manipulate a database using PHP.
Section 1: Overview

Recall that we said that dynamic and e-commerce websites use databases to store the content that is loaded into a web page when the page is requested by the user.

The Interactive Web Development course teaches how to use some of the features of JavaScript to make web pages interactive.

However, JavaScript is primarily a client-side language and therefore is not the best choice for dynamically-generated content.

This class will introduce you to one of the most widely used server-side languages, PHP.

Here is a thorough "Introduction to PHP".

Section 2: PH what?

PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.

PHP originally stood for Personal Home Page, but now represents the recursive acronym PHP: Hypertext Preprocessor.

PHP is a server-side language.

The key difference between JavaScript and PHP is the stage of loading the web page at which these embedded programs are executed.

Whereas client-side languages give you control over how a page behaves once it's displayed by the browser, server-side languages let you generate customized pages on the fly before they’re even sent to the browser.

When the browser receives the page, all it sees is standard HTML code, hence the name – server-side language.

How the 
               Internet Works.

How the Internet Works

Section 3: PHP vs. JavaScript or PHP plus JavaScript?

All browsers support the output of PHP code. However, due to security concerns some people disable JavaScript in their browsers unless they are visiting a fully trusted site.

It is quite common to use them both, especially when site content is stored in a database.

Since PHP pages work well on all platforms, a particular strength is that it can be used to develop websites on a desktop system and then deployed on industrial-strength and secure servers.

JavaScript vs. PHP

Benefits of each...

More comparisons here.

Alternative languages

Section 4: Example

As noted, PHP is embedded in your HTML code, with a .php extension rather than .htm or .html.

Let’s look back at a simple example (today1.php / today1.php.txt):

<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Today's Date</title>
</head>

<body>
<p>Today's date (according to this web server) is <br/>
<?php
date_default_timezone_set('America/Denver');
echo date('l, F dS Y.');
?>
</p>
</body>
</html>

Most of this is plain HTML; however, the line between <?php and ?> is PHP code.

Look at the page source using View | Page Source. Notice that all signs of the PHP code have disappeared; in its place, the output of the script has appeared, and it looks just like standard HTML.

This example demonstrates several advantages of server-side scripting:

Section 5: Resources