You are here

function _captcha_generate_captcha_session in CAPTCHA 7

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

Helper function for generating a new CAPTCHA session.

Parameters

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

int $status: the initial status of the CAPTHCA session.

Return value

int the session ID of the new CAPTCHA session.

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

File

./captcha.inc, line 159
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());

  // Insert an entry and thankfully receive the value of the autoincrement field 'csid'.
  $captcha_sid = db_insert('captcha_sessions')
    ->fields(array(
    'uid' => $user->uid,
    'sid' => session_id(),
    'ip_address' => ip_address(),
    'timestamp' => REQUEST_TIME,
    'form_id' => $form_id,
    'solution' => $solution,
    'status' => $status,
    'attempts' => 0,
  ))
    ->execute();
  return $captcha_sid;
}