function image_captcha_image in CAPTCHA 5.3
Same name and namespace in other branches
- 6.2 image_captcha/image_captcha.user.inc \image_captcha_image()
- 6 image_captcha/image_captcha.user.inc \image_captcha_image()
- 7 image_captcha/image_captcha.user.inc \image_captcha_image()
menu callback function that generates the CAPTCHA image
1 string reference to 'image_captcha_image'
- image_captcha_menu in image_captcha/
image_captcha.module - Implementation of hook_menu().
File
- image_captcha/
image_captcha.module, line 228 - Implementation of image CAPTCHA for use with the CAPTCHA module
Code
function image_captcha_image($seed = NULL) {
if (!$seed) {
return;
}
// Only generate captcha if code exists in the session.
if (isset($_SESSION['image_captcha'][$seed])) {
$code = $_SESSION['image_captcha'][$seed];
// Unset the code from $_SESSION to prevent rerendering the CAPTCHA.
unset($_SESSION['image_captcha'][$seed]);
require_once drupal_get_path('module', 'image_captcha') . '/image_captcha.user.inc';
// generate the image
$image = @_image_captcha_generate_image($code);
// check of generation was successful
if (!$image) {
watchdog('CAPTCHA', t('Generation of image CAPTCHA failed. Check your image CAPTCHA configuration and especially the used font.'), WATCHDOG_ERROR);
exit;
}
// Send the image resource as an image to the client
drupal_set_header("Content-type: image/jpeg");
// Following header is needed for Konqueror, which would re-request the image
// on a mouseover event, which failes because the image can only be generated
// once. This cache directive forces Konqueror to use cache instead of
// re-requesting
drupal_set_header("Cache-Control: max-age=3600, must-revalidate");
// print the image as jpg to the client
imagejpeg($image);
// Clean up
imagedestroy($image);
exit;
}
}