Difference between revisions of "An Overview of PHP"

From Techotopia
Jump to: navigation, search
(What Exactly is PHP?)
(How Does PHP Work?)
Line 8: Line 8:
  
 
== How Does PHP Work? ==
 
== How Does PHP Work? ==
 +
 +
To develop an understanding of how PHP works it is helpful to first explore what happens when a web page is served to a user's browser.
 +
 +
When a user visits a web site or clicks on a link on a page the browser sends a request to the web server hosting the site asking for a copy of the web page. The web servber receives the request, finds the corresponding web page file on the file system and sends it back, over the internet, to the user's browser.
 +
 +
Typically the web server doesn't pay any attention to the content of the file it has just transmitted to the web browser. As far the web server is concerned the web browser understands the content of the web page file and knows how to interpret and render it so that it appears as the web designer intended.
 +
 +
Now let's consider what kind of web page content a web browser understands. These days a web page is likely to consist of HTML, XHTML and JavaScript. The web browser contains code that tells it waht to do with these types of content. For example, it understands the structure HTML in terms of rendering the page, and it has a JavaScript interpreter built in that know how to execute the instruction in a JavaScript script. A web browser, however, knows absolutely nothing about any PHP script that may be embeeded in an HTML document. if a brwoser was serverd a web page containing PHP it would not know how to interpreet that code.
 +
 +
Given that a web browser knows nothing about PHP in a web page, then clearly something has to be doen with any PHP script in the page before it reaches the browser. This is where the PHP pre-processing module comes in. The PHP module is integrated into the web server. The module tells the web server that when a page is to served that contains PHP script (identified by special markers) that it is pass that script to the PHP pre-processing module and wait. The PHP processing module understands PHP, executes the PHP script written by the web developer.

Revision as of 16:50, 23 May 2007

Having covered The History of PHP in the previous chapter it is now time to provide some detail as to what PHP actually is. In this chapter we will take a high level look at PHP and provide a basic understanding of what it is, what is does and how it does it.

What Exactly is PHP?

PHP is an intuitive, server side scripting language. Like any other scripting langauge it allows develpers to build logic into the creation of web page content and handle data returned from a web browser. PHP also contains a number of extensions that make it easy to interact with databases, extracting data to be displayed on a web page and storing information entered by a web site visitor back into the database.

PHP consists of a scripting language and an interpreter. Like other scripting languages, PHP enables web developers to define the behavior and logic they need in a web page. These scripts are embedded into the HTML documents that are served by the web server. The interpreter takes the form of a module that integrates into the web server, converting the scripts into commands the computer then executes to achieve the results defined in the script by the web developer.

How Does PHP Work?

To develop an understanding of how PHP works it is helpful to first explore what happens when a web page is served to a user's browser.

When a user visits a web site or clicks on a link on a page the browser sends a request to the web server hosting the site asking for a copy of the web page. The web servber receives the request, finds the corresponding web page file on the file system and sends it back, over the internet, to the user's browser.

Typically the web server doesn't pay any attention to the content of the file it has just transmitted to the web browser. As far the web server is concerned the web browser understands the content of the web page file and knows how to interpret and render it so that it appears as the web designer intended.

Now let's consider what kind of web page content a web browser understands. These days a web page is likely to consist of HTML, XHTML and JavaScript. The web browser contains code that tells it waht to do with these types of content. For example, it understands the structure HTML in terms of rendering the page, and it has a JavaScript interpreter built in that know how to execute the instruction in a JavaScript script. A web browser, however, knows absolutely nothing about any PHP script that may be embeeded in an HTML document. if a brwoser was serverd a web page containing PHP it would not know how to interpreet that code.

Given that a web browser knows nothing about PHP in a web page, then clearly something has to be doen with any PHP script in the page before it reaches the browser. This is where the PHP pre-processing module comes in. The PHP module is integrated into the web server. The module tells the web server that when a page is to served that contains PHP script (identified by special markers) that it is pass that script to the PHP pre-processing module and wait. The PHP processing module understands PHP, executes the PHP script written by the web developer.