/** * Generates the captcha question and answer and prepares the * session data. * * @return boolean TRUE when the captcha has been created newly, FALSE * if it already existed. */ protected function generateCaptcha() { if (!parent::generateCaptcha()) { if (is_file($this->imageDir . $this->getSession()->question)) { return false; } // Create a new captcha if file no longer exists $this->getSession()->clear(); $this->getSession()->solved = false; $this->loadAdapter(); } $session = $this->getSession(); $captchaFile = $session->getSessionId() . $this->imageSuffix; // Save image to file file_put_contents($this->imageDir . $captchaFile, $this->adapter->getCAPTCHA()); list($width, $height) = getimagesize($this->imageDir . $captchaFile); $session->question = $captchaFile; $session->imageHeight = $height; $session->imageWidth = $width; $this->garbageCollection(); return true; }