|
HTML Pre-Processing
Engines
pg. 13
Web pages are very static by nature. The HTML
language is great for formatting and displaying text, graphics and other media
in a Web browser, but was never designed to create truly interactive Web sites.
Traditionally, if you wanted your Web site to actually do something you had to
create CGI programs written in a language such as Perl or C that could take
input from a user and produce output based on that information.
Wouldn’t it be nice if there was a way to embed programming statements within
the HTML of a Web page and create dynamic results in different situations?
Perhaps even have your Web pages retrieve or store information in an online
database, or access an automated credit card transaction system all through
easy-to-use HTML style tags? Welcome to the world of HTML pre-processing
engines!
An HTML pre-processor greatly extends the power and flexibility of the HTML
language. Rather than send the raw HTML code directly to the user’s Web browser,
the pre-processor first scans the code for special tags. These special tags can
be used to perform a wide variety of functions from simple math to complex logic
to SQL database interaction. The pre-processor interprets these tags before
returning the HTML code to the user’s browser.
You can think of pre-processing engines as the stagehands that do the work
behind the scenes. In the following diagram, imagine that the WEB SERVICE is a
stage. The USER is part of the audience, and the curtain (represented by the
vertical line) ensures the user gets to sit back and enjoy the show, without
having to worry about what’s “behind the curtain.”

There are two HTML pre-processors that work very
well on your virtual server: PHP and Miva, both of which are completely free.
PHP : Hypertext Pre-Processor
PHP3, formerly known as PHP/FI, is an excellent pre-processing engine that
supports a very robust HTML-embedded scripting language. Much of its syntax is
borrowed from the C, Java and Perl programming languages, with some unique
PHP-specific features thrown in. The goal of the PHP language is to allow Web
developers to quickly write powerful, dynamically generated pages.
Configuring PHP
PHP is already built into your virtual server’s Web service. However, to enable
it, you must tell your virtual server what file extension you would like to
enable PHP for. This is done by verifying that you have the following line
somewhere in your ~/www/conf/srm.conf file:
AddType application/x-httpd-php3 .php3 .php
If this line is not present, PHP will not be enabled. You choose any file
extension you like, and enable multiple file types by adding to the list on the
right side.
Using this default configuration, your virtual server recognizes any file with a
.php or .php3 file extension as a PHP-enhanced Web page. It then searches these
pages, looking for and interpreting the special PHP tags before returning the
page to the end user.
PHP tags take the form of <? tagname; ?> and can be
inserted right into your HTML code. These tags, and the statements inside them,
do not appear in the user’s Web browser because they are interpreted and
replaced by the Web service with the values that result from the statement. For
example, if your source code looked like this:
<html>
<body> <? $age = 40;?>
Hello. You are <? echo $age;?> years old.
</body>
</html>
The PHP tags would be interpreted and the following code would be sent to the
user’s Web browser:
<html>
<body>
Hello. You are 40 years old.
</body>
</html>
Finally, the output from the user’s browser would be:
Hello. You are 40 years old.
PHP also serves as an excellent interface to online databases. PHP supports a
large number of databases, including MySQL – a very popular SQL database.
Complete information about PHP is available at
http://www.php.net
Using PHP For CGI Programs
PHP, is another excellent way to write CGI programs. PHP allows you to combine
your CGI programming and HTML code in a single file rather than placing them in
different locations. There are hundreds of PHP functions that do just about
everything imaginable—from interpreting form results to sending email to
generating fast, dynamic Web content.
PHP programs often run faster than Perl programs, but not as fast a C programs.
They are often quicker to write, but are not as flexible nor as powerful as very
advanced Perl scripts.
Here is an example of a simple PHP CGI program. After configuring PHP, create a
page in your ~/www/htdocs directory called "example.php3" that contains the
following text:
<html>
<head><title>PHP CGI Example</title></head>
<body>
<? if ($NAME):?>
<? echo "Hello $NAME!";?>
<? else:?>
<form method="POST">
What is your name?
<input name=NAME>
<p>
<input type=submit>
</form>
<? endif;?>
</body>
</html>
The ability to place HTML and PHP code together in the same file simplifies
things quite a bit.
Using PHP as a Database Interface
Among its many features, PHP is a great Web interface for mSQL 2.0 and MySQL
databases. Complete information about using PHP as a MySQL database interface
can be found at the PHP Web site:
http://www.php.net/manual/ref.mysql.php3
We suggest that you read and understand our Databases Chapter in its entirety
and then study the MySQL section of the PHP Web site to learn the intricacies of
Web site / database interaction.
Virtual Server Lite |
Virtual Server Standard |
Virtual Server Pro |
Virtual Server Ultra |
1024 megs |
5120 megs |
7680 megs |
12288 megs |
Details |
Details |
Details |
Details |
Order |
Order |
Order |
Order |
|