You are here

function image_captcha_image in CAPTCHA 6

Same name and namespace in other branches
  1. 5.3 image_captcha/image_captcha.module \image_captcha_image()
  2. 6.2 image_captcha/image_captcha.user.inc \image_captcha_image()
  3. 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.user.inc, line 13

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]);

    // generate the image
    $image = @_image_captcha_generate_image($code);

    // check of generation was successful
    if (!$image) {
      watchdog('CAPTCHA', 'Generation of image CAPTCHA failed. Check your image CAPTCHA configuration and especially the used font.', array(), 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;
  }
}