function http_session() { global $php; if (empty($_COOKIE[Session::$sess_name])) { $sess_id = uniqid(RandomKey::string(Session::$sess_size - 13)); $php->response->setcookie(Session::$sess_name, $sess_id, time() + $php->protocol->config['session']['cookie_life']); } else { $sess_id = trim($_COOKIE[Session::$sess_name]); } $session_cache = new Cache($php->protocol->config['session']['cache_url']); Session::$cache_life = $php->protocol->config['session']['session_life']; Session::$cache_prefix = Session::$sess_name; $sess = new Session($session_cache); $_SESSION = $php->request->session = $sess->load($sess_id); $php->session_open = true; $php->session = $sess; }
/** * 设置Form Secret防止,非当前页面提交数据 * @param $page_name * @param $return * @return unknown_type */ static function secret($page_name = '', $length = 32, $return = false) { $secret = uniqid(RandomKey::string($length)); if ($return) { return $secret; } else { $k = 'form_' . $page_name; setcookie($k, $secret, 0, '/'); if (!isset($_SESSION)) { session(); } $_SESSION[$k] = $secret; } }
/** * 使用imagick扩展生成验证码图片 * @param int $img_width * @param int $img_height * @param bool $addRandomLines * @param bool $swirl * @return array */ static function verifycode_imagick($img_width = 80, $img_height = 30, $addRandomLines = true, $swirl = true) { $fontSize = 24; /* imagick对象 */ $Imagick = new \Imagick(); /* 背景对象 */ $bg = new \ImagickPixel(); /* Set the pixel color to white */ $bg->setColor('rgb(235,235,235)'); /* 画刷 */ $ImagickDraw = new \ImagickDraw(); if (is_file(self::$verifyCodeFontFile)) { $ImagickDraw->setFont(self::$verifyCodeFontFile); } $ImagickDraw->setFontSize($fontSize); $ImagickDraw->setFillColor('black'); $code = strtoupper(RandomKey::string(self::$verifyCodeLength)); /* Create new empty image */ $Imagick->newImage($img_width, $img_height, $bg); /* Write the text on the image */ $Imagick->annotateImage($ImagickDraw, 4, 20, 0, $code); /* 变形 */ if ($swirl) { $Imagick->swirlImage(10); } /* 随即线条 */ if ($addRandomLines) { $ImagickDraw->line(rand(0, 70), rand(0, 30), rand(0, 70), rand(0, 30)); $ImagickDraw->line(rand(0, 70), rand(0, 30), rand(0, 70), rand(0, 30)); $ImagickDraw->line(rand(0, 70), rand(0, 30), rand(0, 70), rand(0, 30)); $ImagickDraw->line(rand(0, 70), rand(0, 30), rand(0, 70), rand(0, 30)); $ImagickDraw->line(rand(0, 70), rand(0, 30), rand(0, 70), rand(0, 30)); } /* Draw the ImagickDraw object contents to the image. */ $Imagick->drawImage($ImagickDraw); /* Give the image a format */ $Imagick->setImageFormat('png'); /* Send headers and output the image */ return array('image' => $Imagick->getImageBlob(), 'code' => $code); }