drupal阵列的关键?

时间:2011-03-16 01:06:28

标签: php drupal drupal-6

    /**
 * @param (string) $key
   */
     function _mycaptcha_get_ask($key = NULL) {

  $ask = array(
'Where does a pilot work?' => 'airplane',
'What day is before Saturday' => 'Friday',
'Which letter is the different between here and there' => 't',
 );

  return isset($key) ? $ask[$key] : $ask;
  }


/**
* @param (array) $form
*/
function mycaptcha_ask_form(&$form) {
  $ask = _mycaptcha_get_ask();
 if (isset($_SESSION['mycaptcha_ask_key']) && $ask[$_SESSION['mycaptcha_ask_key']]) {
   $ask_key = $_SESSION['mycaptcha_ask_key'];
  }

  if (!$ask_key) {
   $_SESSION['mycaptcha_ask_key'] = $ask_key = array_rand($ask);
 }

 $form['mycaptcha_ask'] = array(
'#type' => 'textfield',
'#required' => 1,
'#title' =>$ask_key,
'#weight' => -1,
  );
}

代码是从别人那里写的,我无法理解它,尤其是$ _SESSION ['mycaptcha_ask_key']变量。我不知道密钥'mycaptcha_ask_key'来自哪里。

1 个答案:

答案 0 :(得分:1)

$ _SESSION变量用于与为单个用户会话存储的数据进行交互。它的工作方式与$ _POST和$ _GET变量类似。

查看http://au.php.net/manual/en/function.session-start.php