If you've never used PHP, you might be very surprised to learn how easy it is to embed PHP commands in HTML files. The files don't require execute privilege and don't have to be stored in cgi-bin directory to work. In addition, reading and using data from forms is significantly easier since PHP stuffs the data into arrays. The $_POST[name] field, for example, would hold text entered into the "name" field in a form when the form uses the POST method to send the data. The $_GET array provides the same functionality for data sent using the GET method. If you want to write a script that is independent of the method -- no problem: use $_REQUEST. This array contains the elements from the $_GET and $_POST along with the contents of $_FILES, $_COOKIE, $_SERVER and $_ENV as well. What you don't ahve to worry about when using PHP is, therefore, how to read from standard in or the QUERY_STRING variable, how to break the data into a series of "parameter=value" pairs, how to break the parameter/value pairs apart and then unencode their values. PHP takes care of all of this for you.
The only downside that I see to PHP is that it's not likely to be installed on your systems unless you make it so. When I installed it on a Solaris 9 box, I also had to install about eight additional packages and do some very modest reconfiguration of my Apache server to get it working.
PHP has a look which reminds one of C and Perl. That is, it assigns variables using a $name=value; syntax, uses // or /* and */ for comments and includes a wide set of functions, array capabilities and other high level language functionality. But just look how easily you can set up a form and send email in a single file:
<?php
if (isset($_REQUEST['email']))
//if form is filled out, send email
{
//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail( "myself@example.com", "Subject: $subject",
$message, "From: $email" );
echo "Thank you. Your request has been sent.";
}
else
//if "email" is not filled out, display the form
{
echo "<form method='post' action='tryme.php'>
Your Email: <input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Please explain your concern:<br />
<textarea name='message' rows='10' cols='40'>
</textarea><br />
<input type='submit' />
</form>";
}
?>
If you'd like a gentle but very effective introduction to PHP, I highly recommend the tutorial available at the W3Schools URL:
http://www.w3schools.com/php/default.asp
Once you've gotten your feet wet by wading through the example scripts, you might be ready to delve into O'Reilly's PHP Cookbook. The second edition of this task-oriented text contains hundreds of extremely useful code examples.
Sign up for ITworld's Daily newsletter
Follow ITworld on Twitter @IT_world
Esther Schindler
If the comments are ugly, the code is ugly
claird
SVG a graphics format for 21st century
pasmith
Take Chrome OS for a test spin
Sandra Henry-Stocker
Solaris Tip: Have Your Files Changed Since Installation?
jfruh
Android fragments vs. the iPhone monolith
mikelgan
What Gizmodo missed about the Pro WX Wireless USB disk drive
Sidekick: The Good News & the Bad News
Either way you look at it Microsoft Data Center management did not follow standards or best practices in this failure. In which case it makes me wonder more about the outsourcing of corporate data much less personal data.
- mburton325
Join the conversation here
Quick, practical advice for IT pros. Made fresh daily.
Want to cash in on your IT savvy? Send your tip to tips@itworld.com. If we post it, we'll send you a $25 Amazon e-gift card.














Easy AND Powerful
Good article. PHP has been around for a while and I came to it only recently to do a project. Having heard about it for several years before and not fully understanding its great power and flexibility. I love its integration with databases.I have not found any web programming "problem" that can't be addressed using PHP.
Cheers PHP!