set() public static method

设置某个Cookie值
public static set ( string $name, mixed $value, integer $expire, string $path = '', string $domain = '' ) : void
$name string 要设置的cookie的名称
$value mixed 要设置的值
$expire integer 过期时间
$path string path
$domain string domain
return void
Esempio n. 1
0
 /**
  * 生成数字计算题验证码
  *
  * @param string $type
  * @param int $width
  * @param int $height
  * @param string $font
  * @param string $verifyName
  *
  * @return void
  */
 public static function calocVerify($type = 'png', $width = 170, $height = 45, $font = 'tahoma.ttf', $verifyName = 'verifyCode')
 {
     $la = rand(0, 9);
     $ba = rand(0, 9);
     $randnum = rand(1, 3);
     if ($randnum == 3) {
         if ($la < $ba) {
             $tmp = $la;
             $la = $ba;
             $ba = $tmp;
         }
     }
     $randarr = array(1 => $la + $ba, 2 => $la * $ba, 3 => $la - $ba);
     $randstr = $randarr[$randnum];
     $randResult = array(1 => $la . '+' . $ba . '=?', 2 => $la . '*' . $ba . '=?', 3 => $la . '-' . $ba . '=?');
     $randval = $randResult[$randnum];
     $authKey = md5(mt_rand() . microtime());
     \Cml\Http\Cookie::set($verifyName, $authKey);
     \Cml\Model::getInstance()->cache()->set($authKey, $randstr);
     //$width = ($length * 10 + 10) > $width ? $length * 10 + 10 : $width;
     if ($type != 'gif' && function_exists('imagecreatetruecolor')) {
         $im = imagecreatetruecolor($width, $height);
     } else {
         $im = imagecreate($width, $height);
     }
     $r = array(225, 255, 255, 223);
     $g = array(225, 236, 237, 255);
     $b = array(225, 236, 166, 125);
     $key = mt_rand(0, 3);
     $backColor = imagecolorallocate($im, $r[$key], $g[$key], $b[$key]);
     //背景色(随机)
     $borderColor = imagecolorallocate($im, 100, 100, 100);
     //边框色
     imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);
     imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor);
     $stringColor = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));
     // 干扰
     for ($i = 0; $i < 10; $i++) {
         imagearc($im, mt_rand(-10, $width), mt_rand(-10, $height), mt_rand(30, 300), mt_rand(20, 200), 55, 44, $stringColor);
     }
     for ($i = 0; $i < 25; $i++) {
         imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $stringColor);
     }
     for ($i = 0; $i < 5; $i++) {
         //  imagestring($im, 5, $i * 10 + 5, mt_rand(1, 8), $randval{$i}, $stringColor);
         $x = $i === 0 ? 20 : $i * 50;
         $stringColor = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));
         if ($i == 1 || $i == 3 || $i == 4) {
             $fontSize = $randnum == 3 ? 50 : 28;
             if ($i == 1) {
                 imagettftext($im, $fontSize, 0, $x, 35, $stringColor, CML_EXTEND_PATH . DIRECTORY_SEPARATOR . $font, $randval[$i]);
             } else {
                 $decNum = $i == 3 ? 30 : 55;
                 imagettftext($im, 25, 0, $x - $decNum, 35, $stringColor, CML_EXTEND_PATH . DIRECTORY_SEPARATOR . $font, $randval[$i]);
             }
         } else {
             imagettftext($im, 28, mt_rand(0, 60), $x, 35, $stringColor, CML_EXTEND_PATH . DIRECTORY_SEPARATOR . $font, $randval[$i]);
         }
     }
     self::output($im, $type);
 }
Esempio n. 2
0
 /**
  * 保存当前登录用户的信息
  *
  * @param int $uid 用户id
  * @param bool $sso 是否为单点登录,即踢除其它登录用户
  */
 public static function setLoginStatus($uid, $sso = true)
 {
     $user = ['uid' => $uid, 'expire' => Cml::$nowTime + 3600, 'ssosign' => $sso ? (string) Cml::$nowMicroTime : self::$ssoSign];
     //Cookie::set本身有一重加密 这里再加一重
     $sso && Model::getInstance()->cache()->set("SSOSingleSignOn{$uid}", (string) Cml::$nowMicroTime);
     Cookie::set(Config::get('userauthid'), Encry::encrypt(json_encode($user, JSON_UNESCAPED_UNICODE), self::$encryptKey), 0);
 }
Esempio n. 3
0
 /**
  * 设置用户登录Cookie
  *
  * @param int $uid 用户id
  */
 public static function setLoginStatus($uid)
 {
     $user = array('uid' => $uid, 'expire' => Cml::$nowTime + 3600, 'ssosign' => (string) Cml::$nowMicroTime);
     //Cookie::set本身有一重加密 这里再加一重
     Model::getInstance()->cache()->set("SSOSingleSignOn{$uid}", (string) Cml::$nowMicroTime);
     Cookie::set(Config::get('userauthid'), Encry::encrypt(json_encode($user, PHP_VERSION >= '5.4.0' ? JSON_UNESCAPED_UNICODE : 0), self::$encryptKey), 0);
 }