$char, 'size' => $charSize, 'angle' => $charAngle, 'box' => $bbox ); } // encode value $value = md5(md5(md5($resultString))); // if storage is "session", store the value in session if ($storage == 'session') $_SESSION['captcha'] = $value; // otherwise, store the value in a cookie else setcookie('captcha', $value, time() + 3600, '/'); // either ways, the value will later be read by the form generator // and used to see if the user entered the correct characters // create the image $img = imagecreatetruecolor($imageWidth, $imageHeight); // allocate some colors $white = imagecolorallocate($img, 255, 255, 255); $black = imagecolorallocate($img, 0, 0, 0); // fill the canvas to white imagefilledrectangle($img, 0, 0, $imageWidth, $imageHeight, $white); // write some random characters in the background for ($i = 0; $i <10; $i++) { // ...having random washed-out colors $color = imagecolorallocate($img, rand(150, 200), rand(150, 200), rand(150, 200)); imagettftext( $img, 20, rand($fontAngleVariation[0], $fontAngleVariation[1]), rand(0, $imageWidth), rand(20, $imageHeight) , $color, $font, chr(rand(65, 90)) ); } // draw a bounding rectangle // imagerectangle($img, 0, 0, $imageWidth - 1, $imageHeight - 1, $black); // this is to keep the word centered in the box $left = (($imageWidth - $totalWidth) / 2); // iterate through the chosen characters foreach ($captcha as $values) { // print each character imagettftext( $img, $values['size'], $values['angle'], $left , ($imageHeight + $values['box']['height']) / 2 , $black, $font, $values['char'] ); // compute the position of the next character $left += $values['box']['width'] + $characterSpacing; } // and finally output the image at the specified quality imagejpeg($img, null, $imageQuality); // free memory imagedestroy($img); // if we're performing a file upload } elseif ( isset($_FILES) && is_array($_FILES) && !empty($_FILES) && isset($_GET['form']) && isset($_GET['control']) && isset($_FILES[$_GET['control']]) ) { function process() { // the form that initiated the request $form = $_GET['form']; // the file upload control on the form that initiated the request $control = $_GET['control']; // if file could be uploaded if (isset($_FILES[$_GET['control']])) { // save some information about the uploaded file $file['name'] = $_FILES[$control]['name']; $file['type'] = $_FILES[$control]['type']; $file['error'] = $_FILES[$control]['error']; $file['size'] = $_FILES[$control]['size']; // if there were problems uploading the file } elseif (empty($_POST) && empty($_FILES) && isset($_SERVER['CONTENT_LENGTH']) && isset($_SERVER['CONTENT_TYPE']) && (strpos($_SERVER['CONTENT_TYPE'], 'multipart/form-data') !== false || strpos($_SERVER['CONTENT_TYPE'], 'application/x-www-form-urlencoded') !== false)) { // send these values $file['name'] = ''; $file['type'] = 'unknown'; $file['error'] = 1; $file['size'] = $_SERVER['CONTENT_LENGTH']; } ob_start(); ?>