예제 #1
0
 public function start($readonly = false)
 {
     $this->readonly = $readonly;
     $this->open = true;
     $sessid = Cookie::get(self::$cookie_key);
     if (empty($sessid)) {
         $sessid = \RandomKey::randmd5(40);
         Cookie::set(self::$cookie_key, $sessid, self::$cache_life);
     }
     $_SESSION = $this->load($sessid);
 }
예제 #2
0
 public function start($readonly = false)
 {
     if ($this->use_php_session) {
         session_start();
     } else {
         $this->readonly = $readonly;
         $this->open = true;
         $sessid = get_cookie(self::$cookie_key);
         if (empty($sessid)) {
             $sessid = RandomKey::randmd5(40);
             set_cookie(self::$cookie_key, $sessid, self::$cache_life);
         }
         $_SESSION = $this->load($sessid);
     }
 }
예제 #3
0
 public function start($readonly = false)
 {
     $this->isStart = true;
     if ($this->use_php_session) {
         session_start();
     } else {
         $this->readonly = $readonly;
         $this->open = true;
         $sessid = Cookie::get(self::$cookie_key);
         if (empty($sessid)) {
             $sessid = RandomKey::randmd5(40);
             Cookie::set(self::$cookie_key, $sessid, self::$cookie_lifetime);
         }
         $_SESSION = $this->load($sessid);
     }
     \Swoole::$php->request->session = $_SESSION;
 }
예제 #4
0
파일: server.php 프로젝트: superwmh/swoole
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;
}
예제 #5
0
 /**
  * 生成验证码,使用TTF字体
  * @param $font
  * @param $img_width
  * @param $img_height
  * @return unknown_type
  */
 static function verify_ttf($font, $width = 180, $height = 130)
 {
     if (empty($_SESSION)) {
         session_start();
     }
     $length = 4;
     $code = RandomKey::getChineseCharacter(4);
     $width = $length * 45 > $width ? $length * 45 : $width;
     $_SESSION['authcode'] = md5($code);
     $im = imagecreatetruecolor($width, $height);
     $borderColor = imagecolorallocate($im, 100, 100, 100);
     //边框色
     $bkcolor = imagecolorallocate($im, 250, 250, 250);
     imagefill($im, 0, 0, $bkcolor);
     imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor);
     // 干扰
     for ($i = 0; $i < 15; $i++) {
         $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         imagearc($im, mt_rand(-10, $width), mt_rand(-10, $height), mt_rand(30, 300), mt_rand(20, 200), 55, 44, $fontcolor);
     }
     for ($i = 0; $i < 255; $i++) {
         $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $fontcolor);
     }
     for ($i = 0; $i < $length; $i++) {
         $fontcolor = imagecolorallocate($im, mt_rand(0, 120), mt_rand(0, 120), mt_rand(0, 120));
         //这样保证随机出来的颜色较深。
         $codex = self::msubstr($code, $i, 1);
         imagettftext($im, mt_rand(16, 20), mt_rand(-60, 60), 40 * $i + 20, mt_rand(30, 35), $fontcolor, $font, $codex);
     }
     Header("Content-type: image/png");
     //告诉浏览器,下面的数据是图片
     ImagePng($im);
     //生成png格式
     ImageDestroy($im);
 }
예제 #6
0
파일: Form.php 프로젝트: ruziyi/framework
 /**
  * 设置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;
     }
 }
예제 #7
0
 function save($name, $filename = null, $allow = null)
 {
     //检查请求中是否存在上传的文件
     if (empty($_FILES[$name]['type'])) {
         $this->error_msg = "No upload file '{$name}'!";
         $this->error_code = 0;
         return false;
     }
     //最终相对目录
     $base_dir = empty($this->sub_dir) ? $this->sub_dir : $this->base_dir . "/" . $this->sub_dir;
     //切分目录
     if ($this->shard_type == 'randomkey') {
         if (empty($this->shard_argv)) {
             $this->shard_argv = 8;
         }
         $up_dir = $base_dir . "/" . RandomKey::randmd5($this->shard_argv);
     } elseif ($this->shard_type == 'user') {
         $up_dir = $base_dir . "/" . $this->shard_argv;
     } else {
         if (empty($this->shard_argv)) {
             $this->shard_argv = 'Ym/d';
         }
         $up_dir = $base_dir . "/" . date($this->shard_argv);
     }
     //上传的最终绝对路径,如果不存在则创建目录
     $path = WEBPATH . $up_dir;
     if (!is_dir($path)) {
         if (mkdir($path, 0777, true) === false) {
             $this->error_msg = "mkdir path={$path} fail.";
             return false;
         }
     }
     //MIME格式
     $mime = $_FILES[$name]['type'];
     $filetype = $this->mime_type($mime);
     if ($filetype === 'bin') {
         $filetype = self::file_ext($_FILES[$name]['name']);
     }
     if ($filetype === false) {
         $this->error_msg = "File mime '{$mime}' unknown!";
         $this->error_code = 1;
         return false;
     } elseif (!in_array($filetype, $this->allow)) {
         $this->error_msg = "File Type '{$filetype}' not allow upload!";
         $this->error_code = 2;
         return false;
     }
     //生成文件名
     if ($filename === null) {
         $filename = RandomKey::randtime();
         //如果已存在此文件,不断随机直到产生一个不存在的文件名
         while ($this->exist_check and is_file($path . '/' . $filename . '.' . $filetype)) {
             $filename = RandomKey::randtime();
         }
     } elseif ($this->overwrite === false and is_file($path . '/' . $filename . '.' . $filetype)) {
         $this->error_msg = "File '{$path}/{$filename}.{$filetype}' existed!";
         $this->error_code = 3;
         return false;
     }
     if ($this->shard_type != 'user') {
         $filename .= '.' . $filetype;
     }
     //检查文件大小
     $filesize = filesize($_FILES[$name]['tmp_name']);
     if ($this->max_size > 0 and $filesize > $this->max_size) {
         $this->error_msg = "File size go beyond the max_size!";
         $this->error_code = 4;
         return false;
     }
     $save_filename = $path . "/" . $filename;
     //写入文件
     if (self::moveUploadFile($_FILES[$name]['tmp_name'], $save_filename)) {
         //产生缩略图
         if ($this->thumb_width and in_array($filetype, array('gif', 'jpg', 'jpeg', 'bmp', 'png'))) {
             if (empty($this->thumb_dir)) {
                 $this->thumb_dir = $up_dir;
             }
             $thumb_file = $this->thumb_dir . '/' . $this->thumb_prefix . $filename;
             Image::thumbnail($save_filename, WEBPATH . $thumb_file, $this->thumb_width, $this->thumb_height, $this->thumb_qulitity);
             $return['thumb'] = $thumb_file;
         }
         //压缩图片
         if ($this->max_width and in_array($filetype, array('gif', 'jpg', 'jpeg', 'bmp', 'png'))) {
             Image::thumbnail($save_filename, $save_filename, $this->max_width, $this->max_height, $this->max_qulitity);
         }
         $return['name'] = "{$up_dir}/{$filename}";
         $return['size'] = $filesize;
         $return['type'] = $filetype;
         return $return;
     } else {
         $this->error_msg = "move upload file fail. tmp_name={$_FILES[$name]['tmp_name']}|dest_name={$save_filename}";
         $this->error_code = 2;
         return false;
     }
 }
예제 #8
0
<?php

require __DIR__ . '/vendor/autoload.php';
$url = $_GET['url'];
$userUrl = $_GET['userUrl'];
if ($userUrl && strlen($userUrl) > 10) {
    $errMsg = 'Too long url!';
}
if ($_GET['toTime'] && !preg_match('/^[0-9]{1,3}$/', $_GET['toTime'])) {
    $errMsg = 'Not correct time!';
}
if ($_GET['toTime']) {
    $toTime = strftime("%Y-%m-%d %H:%M:%S", time() + $_GET['toTime'] * 3600);
} else {
    $toTime = '0000-00-00 00:00:00';
}
$dbIni = parse_ini_file('config_db.ini');
$message = new GetResult($dbIni['connection'], $dbIni['user'], $dbIni['password']);
$message->url = $url;
$message->toTime = $toTime;
if (!$userUrl) {
    $randomUrl = new RandomKey();
    $userUrl = $randomUrl->getSymbols();
}
$message->userUrl = $userUrl;
include 'index.php';
예제 #9
0
 /**
  * 生成汉字验证码
  * @param $font
  * @param $width
  * @param $height
  * @return array
  */
 static function verifycode_chinese($font, $width = 180, $height = 60)
 {
     $length = 4;
     $angle = 45;
     $width = $length * 45 > $width ? $length * 45 : $width;
     $im = imagecreatetruecolor($width, $height);
     $borderColor = imagecolorallocate($im, 100, 100, 100);
     //边框色
     $bkcolor = imagecolorallocate($im, 250, 250, 250);
     imagefill($im, 0, 0, $bkcolor);
     imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor);
     // 干扰
     for ($i = 0; $i < 5; $i++) {
         $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         imagearc($im, mt_rand(-10, $width), mt_rand(-10, $height), mt_rand(30, 300), mt_rand(20, 200), 55, 44, $fontcolor);
     }
     for ($i = 0; $i < 255; $i++) {
         $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $fontcolor);
     }
     $code = '';
     for ($i = 0; $i < $length; $i++) {
         $fontcolor = imagecolorallocate($im, mt_rand(0, 120), mt_rand(0, 120), mt_rand(0, 120));
         //这样保证随机出来的颜色较深。
         $codex = RandomKey::getChineseCharacter(1);
         $code .= $codex;
         @imagettftext($im, mt_rand(16, 20), mt_rand(-$angle, $angle), 40 * $i + 20, mt_rand(30, 35), $fontcolor, $font, $codex);
     }
     ob_start();
     ImagePng($im);
     $data = ob_get_clean();
     ImageDestroy($im);
     return array('code' => $code, 'image' => $data);
 }