Perl vs. PHP
Perl is a widely-used programming language used to process CGI (Common Gateway Interface) information. Unfortunately, it is challenging to write and debug. Let's begin with an HTML form to collect a visitor's first name and last name (we'll call it form.html):
<html> <body> <form action="cgi-bin/name.cgi" method="post"> What is your first name?<INPUT type=text name=first><BR> What is your last name?<INPUT type=text name=last><BR> <INPUT type=submit> </form> </body> </html>
Here is an example of a Perl script (we'll call it name.cgi). It should be noted that this script will have to be placed in a special directory (often called cgi-bin) which the web server knows about and is configured to allow program execution. The permissions of the script must be set to allow execution as well. Getting this all working can be complicated.
#!/usr/bin/perl -Tw # askname.cgi from PROFESSIONAL APACHE use CGI; use strict; my $cgi=new CGI; print $cgi->header(); print $cgi->start_html("CGI Demo"); print "Hello, ",$cgi->param("first")," ",$cgi->param("last"); print $cgi->end_html();
If we modify the action parameter in the <FORM> tag to point to a PHP script:
<HTML> <BODY> <FORM action="name.php" method=post> What is your first name?<INPUT type=text name=first><BR> What is your last name?<INPUT type=text name=last><BR> <INPUT type=submit> </FORM> </BODY> </HTML>
Here is an HTML page which includes PHP code (which we can call name.php), we can perform the same task as the Perl script in a much simpler and shorter set of code:
<HTML> <BODY> <?php extract($_POST); print "Hello, $first $last"; ?> </BODY> </HTML>
The actual PHP code is quite simple, we are simply printing the contents of the two variables which have been passed from the form. The rest is HTML.