Categories


Introduction to PHP

You’ve probably heard of PHP, but for those not familiar with it, we’re going to take a simplistic look at it in this post. What is PHP? What PHP is not. Why you would use it. How PHP works.

 What is PHP?   Scripting vs. Programming

PHP (Hypertext Preprocessor) is a general purpose scripting language that can be embedded into an HTML document. HTML being the programming language for writing most web pages. A PHP script handles the data before it becomes HTML by way of a script that has been uploaded to the Web or you might say “The code is interpreted by a Web server with a PHP processor module which generates the resulting Web page” – while an HTML page is requested and delivered.  See Fig. 2. below.

 Example: We have a web page on gold and silver – www.goldcoins-silverbullion.com. In an effort to help our clients keep from getting scammed by unscrupulous gold buyers, we wanted to offer a way they could calculate the value of their gold jewelry based on the karat weight and current market value before they sold it. To do this we wrote a PHP script that would calculate this value after the client selected the karat designation then input the weight in grams and the current market value.

Once this information in entered, they click ‘Get Estimate’ and are shown a page displaying the dollar value for their item. See this scrip in action here – or click on the image below.

It is helpful to remember, that when using PHP, you are working with two parts of code.

First,  the code placed inside the HTML page and

second, the PHP script you’ve uploaded to the server that causes the action to occur on the web page.

 What PHP is not –

One of the more confusing aspects of PHP is that unlike using a JavaScript, the PHP action cannot be used for client side features like you might see on some web pages, i.e., mouse-overs, pop-ups, image enlarging, etc. The PHP action takes place server-side and is then displayed on the web page.

Why you would us it

One reason you would use it is that PHP is a better alternative than CGI (Common Gateway Interface), ASP (Active Server Pages), and Cold Fusion to name a few. If you are simply using HTML your pages will not have any dynamic behavior or offer any way for your visitor to respond or interact. Another feature is that PHP can work with files, databases, and handle email – as well as many other things simple HTML cannot do. Aside from these behavioral features, some other benefits of PHP are:

  • Easier to learn and use than other languages, i.e, Perl
  • Written specifically for web page construction
  • Free and cross-platform
  • Widely used
How PHP works

We stated that PHP is a server side language where the code you write resides on a host computer (i.e., Host Gator) that serves web pages via browsers.

Once your client visits your page, their ISP (Internet Service Provider) directs their request to the appropriate server holding the information.

The server then reads the PHP code and processes it, in effect creating the HTML page that is displayed to the client. See Fig. 1 below.

Note: With reference to our gold example above, the HTML web page containing the PHP script has an .html extension, while the calculated gold value results are shown on a page that has a .php extension. How the action takes place and how the results are displayed are defined in the PHP script.

Conclusion

This should give you a brief  idea  of what PHP is and how it might work.   If you would like to learn more about PHP, the Visual Quickstart Guide by Larry Ullman is a great place to begin. As with all of the Quick Start Guides that we use and love – Larry’s  book uses pictures rather than lengthy explanations. Or, you can visit  http://www.php.net/  for tutorials, scripts, and other helpful information.


Comments are closed.