Article Listing 1 Listing 2 Listing 3 Listing 4
Table 1 apr2007.tar

Listing 1 Code sample for CAPTCHAs

<?
$sCaptchaText=rand(100000);
$_SESSION['captcha']=$nCaptchaID;
?>
<img src="captcha.gif?id=<?= $nCaptchaID ?>">

captcha.gif would include code like:

<?

# Start out with due diligence validation.
if ( key_exists('id',$_GET) && is_int($_GET['id']) ) {
# create characters based on the random ID.
  $sText=substr(sha1(concat($_GET['id'].'somesecret')),0,8);
# create image (function not shown here)
  print CreateImage($sText);
} else {
  header("Location: error_captcha.gif");
}
?>