You are here

function _captcha_generate_captcha_session in CAPTCHA 6.2

Same name and namespace in other branches
  1. 8 captcha.inc \_captcha_generate_captcha_session()
  2. 7 captcha.inc \_captcha_generate_captcha_session()

Helper function for generating a new CAPTCHA session.

Parameters

$form_id the form_id of the form to add a CAPTCHA to.:

$status the initial status of the CAPTHCA session.:

Return value

the session ID of the new CAPTCHA session.

1 call to _captcha_generate_captcha_session()
captcha_process in ./captcha.module
Process callback for CAPTCHA form element.

File

./captcha.inc, line 122
General CAPTCHA functionality and helper functions.

Code

function _captcha_generate_captcha_session($form_id = NULL, $status = CAPTCHA_STATUS_UNSOLVED) {
  global $user;

  // Initialize solution with random data.
  $solution = md5(mt_rand());
  db_query("INSERT into {captcha_sessions} (uid, sid, ip_address, timestamp, form_id, solution, status, attempts) VALUES (%d, '%s', '%s', %d, '%s', '%s', %d, %d)", $user->uid, session_id(), ip_address(), time(), $form_id, $solution, $status, 0);
  $captcha_sid = db_last_insert_id('captcha_sessions', 'csid');
  return $captcha_sid;
}