PHP Tutorial Video 1: How PHP Works

Uploaded by iLearnProgramming on 08.09.2010

Welcome to this PHP Video Tutorial series for Beginners.
As a prerequisite of this series of videos, you should have a good understanding of
basic HTML. If you don't, you can search the playlists for "HTML Tutorials".
In this video, we are going to learn what PHP is, and how PHP works.
The first three videos, including this one, will be a general introduction to PHP.
If you already know how PHP works, and already have a server with PHP installed ready
to go, you may want to skip ahead to the fourth video in this series.
We will begin by taking a look at how a standard HTML file works, and then contrast
that with how a PHP file works.
Anytime we see or use a .htm or .html extension on our files, we know that they are static
HTML files. When we use the .php extension, we know that they are PHP files.
The first important thing to know about PHP, is that we can put any standard HTML into
a .php file, and as long as we have PHP installed
on a server, we can run that file just as if it
were a standard HTML file.
In this diagram, we have a large square that on the left that represents a web site's server.
We can think of a server as an offsite computer where a web site lives.
The smaller square to the right represents the client. A client is the user visiting
the site, who has either typed the server's URL
into the address bar of their browser, or clicked
a link which took them to the server's address.
When we visit a site, we are requesting information from that site's server. In this example,
let's say we're requesting index.html. As the web site's server receives our request,
it will find index.html, and shoot it right back to
us, displayed as a web page
in our browser.
As you can see from the diagram, this way of requesting a file is very static, and very
boring. The HTML file that we requested will be the
exact same, no matter how many times we request it.
The only time that file will change is when the file is physically updated by the web
site's administrator, which could occur weekly, monthly,
or never!
Now, let's look at what happens when we request a PHP file. For this example, let's call it
index.php. This time, notice the small square inside the Server. PHP is installed on this
server, and the smaller square represents the PHP Interpreter, which runs with the server.
As the user requests this page, instead of sending us a static HTML page, the server
is going to "Hand off" index.php to the PHP interpreter
installed on the server.
While the index.php file is being interpreted, it will have access to other Data. This data
may be a database also on the server, other files
on the server, or could be data from virtually anywhere. For example, this index.php
file may be using data from Twitter, Facebook, or Google!
Once the PHP file is interpreted, we are left with an HTML page. No PHP will be sent to
our user, only HTML which was just assembled on the fly.
As you can see, this procedure is dynamic. Using PHP, we can now create HTML that updates
itself based on what the user requests. For example, if the
user requests to Log In to a site, the HTML they see after
they click submit will be different depending on if they entered the correct information,
and once logged in, we may want them to have a totally
unique member's area based on their settings, preferences, and
This diagram shows how PHP works in simple terms, but only represents some of what PHP
can do. PHP can also have send emails,create/edit/delete
files or folders on our server, and many other abilities
that we'll be getting into as we proceed.
As shown by this illustration, PHP is server-side. Some important things to know, is that once
the server sends the HTML to our user, PHP's job is done.
We can't make PHP do anything else after this point
unless the client sends a new request to the server.
Please remember to subscribe to this channel, see you next time.