How PHP Works
When you understand this article, you will have an intuitive
understanding of what PHP is and a better grasp of what is
possible to do with it.
You already understand that when you surf the internet your
browser gets web pages from other computers. These computers
are called servers.
You click on one of a selection of links or type a URL into
your browser's address bar and your browser requests that
web page from a server. The web page is then sent to your
browser, where you can view it.
Let's compare the process to ordering a home entertainment
system over the telephone. You have the catalog open in
front of you and you tell the server (the order person
you're talking to) which model you want. Your order gets
sent to your home, where you can use it.
Most home entertainment system catalogs have systems
pre-configured for immediate delivery. These are listed in
the catalog with product IDs. Everybody who orders the same
product ID from the catalog is sent an identical system.
Most servers have web pages ready to be sent to the browser
as is. These are static web pages. Every browser that
requests a specific static web page is sent an identical
page.
Some home entertainment system catalog companies allow
customers to custom configure entertainment systems.
Configuration options determine what can and can not be
configured.
Customers provide the configuration information when they
order. The company then constructs each requested system
accordingly and sends it to the customer.
Some servers have web pages that can be customized. PHP in
the web page source code determines how the customizations
shall be done.
Browsers provide customization information with cookies, or
by other means, like providing the URL of the web page where
the link was clicked or the identification of the browser
itself. The server then customizes each requested web page
accordingly and sends it to the browser.
Some home entertainment system catalog companies customize
their products according to, as examples, customer
demographics, whether or not it is a repeat customer, how
much the customer has previously spent, the customer's
marital status, or in response to market changes in music
or video.
PHP code in a web page can customize the contents according
to, as examples, time of day, IP address of the browser, how
many other pages have already been viewed, the general speed
of the Internet, how busy the servers are, or in response to
upcoming holidays or world events.
All PHP customizations are completed by the server before
sending the web page to the browser. The web page sent to
the browser does not contain the PHP code, as the code has
already accomplished it's purpose.
PHP can cause a part of the web page to be different
depending on the browser or even the individual visitor.
It might insert a special message when the visitor arrives
from a search engine, for example, or otherwise an
invitation to take a survey.
PHP can utilize any data and software it can access on the
server to custom-build a web page for your site visitors, in
the format they find most pleasing. In some cases, the PHP
code might also access data and software on other servers.
Services that provide personal portal pages are a good
example. The blog synopses you prefer to keep up to date
with are on the page. The weather widget displays the
weather for the area you're interested in. The news
headlines all pertain to the subjects you previously asked
for. Your own picture, or that of a loved one or a hero can
be on the page.
The web page content, the formatting, the colors, and even
the placement of the various sections can reflect your
personal preferences within the range of what the server
has to offer.
PHP has within its power the ability to let you deliver
personalization even to that degree for your own site
visitors.
Individual visitor preferences can be kept in a database on
the server. A cookie with the visitor's browser can contain
a record number or other index to the data record.
When the visitor arrives at your web site and the browser
asks the server for a web page, the cookie tells the PHP
code which data record the visitor's preferences are stored
in. The web page is created accordingly and then sent to the
browser.
PHP can do a lot of other things, also. For example, it can
create images and PDF documents on-the-fly, maintain
databases, talk to other servers, and compress files. It can
compose and send email, log visitor activity, and accomplish
many other tasks.
So, how about a real-world example?
The Server Snooper was originally designed to determine what
kind of server software is in use where a domain is hosted.
When you load the Server Snooper page, it asks for the URL
of a web page on the server being snooped. When you click
the button, the PHP code:
-
Retrieves the web page at the URL you provided.
-
Extracts the header portion of the web page it
retrieved from the web page's content.
-
Inserts the header portion into the Server Snooper
web page.
-
Sends the Server Snooper web page to your browser
with the extracted header portion embedded in the
content.
You end up at the same URL but with the extracted header
portion embedded within it.
The header almost always identifies the software of the
server a domain is hosted on. Sometimes, the identification
includes version numbers.
The header also contains the response code (200 if all is
okay, 404 if page not found, and so forth). And the header
usually contains still more information, the content type
and content length being two common ones.
With the overview you now have, you can better decide
whether or not to pursue a greater understanding of PHP and,
possibly, learn how to build PHP programs to do the tasks
you want done.
Will Bontrager
© Bontrager Connection, LLC
Please note:
Articles on this website are presented "as is". However -
If you have a question about a CGI script, HTML, CSS, PHP, or JavaScript
Ask one of our Experts and you'll have your answer!
Click here for details.