Specifications
//create a unique file name
$infile = tempnam(“”, “pgp”);
$outfile = $infile.”.asc”;
//write the user’s text to the file
$fp = fopen($infile, “w”);
fwrite($fp, $body);
fclose($fp);
//set up our command
$command = “/usr/local/bin/gpg -a \\
--recipient ‘Luke Welling <luke@tangledweb.com.au>’ \\
--encrypt -o $outfile $infile”;
// execute our gpg command
system($command, $result);
//delete the unencrypted temp file
unlink($infile);
if($result==0)
{
$fp = fopen($outfile, “r”);
if(!$fp||filesize ($outfile)==0)
{
$result = -1;
}
else
{
//read the encrypted file
$contents = fread ($fp, filesize ($outfile));
//delete the encrypted temp file
unlink($outfile);
mail($to_email, $title, $contents, “From: $from\n”);
echo “<h1>Message Sent</h1>
<p>Your message was encrypted and sent.
<p>Thank you.”;
}
}
if($result!=0)
{
echo “<h1>Error:</h1>
E-commerce and Security
P
ART III
344
LISTING 15.2 Continued
19 7842 CH15 3/6/01 3:40 PM Page 344










