PHP: Open-Source Web Scripting For The Masses
by Charles J. Scheffold
What is PHP?
PHP is a server-side, cross-platform, HTML embedded scripting language. Because of its ease of use and open-source license, PHP allows the average web developer to enhance a web site with dynamic content that would otherwise be available only on large corporate sites. Also, since PHP is a server-side language, no specific web browser or plug-in is required on the user end. This means that a web site created using PHP is accessible to all visitors regardless of their software setup. In fact, I bet you didn't realize that this web page is using PHP right now!

How does PHP work?
The PHP module operates on the server-side between your web server and the user's browser. Once the module is installed into the web server, PHP is entirely self-sufficient and requires no technical knowledge to use. It transparently processes scripts within web pages before they are transferred to the web browser (the PHP preprocessor does the work of figuring out what is PHP code and what is not). Not only does this allow creation of customized dynamic content, but in comparison to JavaScript or another client-side scripting language, it protects your code from theft and unscrupulous activities (such as gaining information about your web server which might be critical to a hacker).

Because it is not a compiled language, PHP has a great advantage over CGI as well. Changes can be made to existing scripts without the complications of recompiling or locating long lost source code. This feature also makes it highly portable among various operating systems.

The following is a simple "Hello World" example to demonstrate how PHP might be used from within a web page:

HTML Source:
<HTML>
<HEAD><TITLE>Hello World</TITLE></HEAD>
<BODY>
<?php echo "Hello World!<P>"?>
</BODY>
</HTML>

Resulting Output:
Hello World!

I'm sure many of you may be asking, what's so great about that? Just think: you now have the capability of interrupting your HTML tags at any time and entering REAL code. Although this simple example only demonstrates the "echo" function, PHP is a fully structured programming language. Think of it as a cross between C and HTML with all of the advantages of each.

Before I start listing some of the features and advantages of PHP, here is one more example using some of PHP's internal variables which will show you something about yourself that you might not know:

HTML Source:
<HTML>
<HEAD><TITLE>Display Info</TITLE></HEAD>
<BODY>
<?php
 echo "<B>Your IP Address:</B> $REMOTE_ADDR <BR>"
 echo "<B>Your Browser:</B> $HTTP_USER_AGENT <P>"
?>
</BODY>
</HTML>

Resulting Output:
Your IP Address: 54.198.45.0
Your Browser: claudebot

Advantages Over Other "Web Languages"
It's difficult to compare PHP with other "web languages" since they are all very different from one another (for comparison purposes PHP is most similar to ASP in function). However, the following is a brief breakdown of some of the key features present in a few of them:

Language Type Pros Cons
PHP Server-side Scripting
  • Server-side
  • Easy to use and learn
  • Very fast optimized execution
  • Powerful database connectivity
  • Publicly supported
  • Open-source (expand it as you please!)
  • Available for many platforms (Linux, Windows, UNIX)
  • FREE at http://www.php.net
  • Requires technical knowledge to compile and set it up on a server
  • Problems with an open-source architecture are still being debated by the industry
Microsoft
ASP
Server-side Scripting
  • Server-side
  • Commercially supported
  • Powerful database connectivity
  • Supported only by Microsoft web servers
  • Expensive for the average user
  • Available only on the Windows platform
JavaScript Client-side Scripting
  • Easy to learn
  • Widely supported
  • Can act directly on HTML elements
  • Platform independent
  • Speed depends on user's machine
  • Scripts download into browser (increases download time and sacrifices security)
  • Not standardized - features vary depending on browser support
Java Client-side Application
  • Easy to learn
  • Powerful object-oriented design capabilities
  • Can create entire self-contained programs
  • Platform independent
  • Database access
  • Speed depends on user's machine
  • Applets download into browser (increases download time)
  • Not supported by all browsers
  • Requires graphical interface

Graduating Soon? Why You Should Check Out PHP!
Think you can get away with just Visual Basic and ASP? Think again! PHP is becoming very popular with even the largest corporations. Since many companies are switching to Linux as their server platform, Microsoft products are not an option for web development. Big businesses with more money than Bill Gates has in his mattress need you to program in PHP! Tell them you know PHP and they will show you the money! Try searching for "PHP" on www.hotjobs.com and see for yourself.

PHP Resources: Learn More!
http://www.php.net The home of PHP! Downloads and online manual available. The best place to start if you are looking for information.
http://www.phpwizard.net Tutorials, examples, and articles.
http://www.hotscripts.com/PHP Plenty of example scripts, a web forum, and more.

Question For Discussion
What do you think you could use PHP for? (Be creative!) Would it be a technology you would take into consideration when developing a web site?

Conclusion
PHP has so many uses that I cannot possibly touch upon them all in this short presentation. Whether you are putting together a gigantic corporate web site or simply a list of links on your web page that needs frequent updating, PHP can save you a lot of time. Update your web site by changing data in a Microsoft Access table, set up a discussion board, generate images in realtime... it's all possible right now. Database driven web sites are becoming more and more mainstream as the web expands and PHP is an excellent starting point. Could you imagine maintaining a web site the size of Yahoo without a good scripting language? Think about it!

To conclude this presentation, I would like to demonstrate a working PHP program which actually does something useful (well, ok maybe it's not that useful to you but it should be fun!) I hope that this brief description of PHP has interested you enough to try it out for yourself.

The barcode.php program generates a legitimate Code 3 of 9 (no it's not 7 of 9's older sister) bar code from a user's input. A real life practical application of this could be to generate a complete inventory list at a "virtual store" which would then be printed out and used for tracking products in the warehouse by barcode. The resulting barcodes could then be scanned by any standard barcode scanner.

Type an alphanumeric string (A-Z, 1-9, spaces) into the box and click "Generate Barcode" to see it in coded form (for testing purposes, 14 characters is the maximum string length).

If you have any questions regarding this presentation, feel free to send me email at cs@wsia.fm