コード例 #1
0
ファイル: Loader.php プロジェクト: admpub/MicroPHP
 public static function setCookieRaw($key, $value, $life = null, $path = '/', $domian = null, $http_only = false)
 {
     header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
     if (!is_null($domian)) {
         $auto_domain = $domian;
     } else {
         $host = CoreInput::server('HTTP_HOST');
         // $_host = current(explode(":", $host));
         $is_ip = preg_match('/^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$/', $host);
         $not_regular_domain = preg_match('/^[^\\.]+$/', $host);
         if ($is_ip) {
             $auto_domain = $host;
         } elseif ($not_regular_domain) {
             $auto_domain = NULL;
         } else {
             $auto_domain = '.' . $host;
         }
     }
     setcookie($key, $value, $life ? $life + time() : null, $path, $auto_domain, CoreInput::server('SERVER_PORT') == 443 ? 1 : 0, $http_only);
     $_COOKIE[$key] = $value;
 }
コード例 #2
0
ファイル: Helper.php プロジェクト: admpub/MicroPHP
 /**
 * 获取入口文件所在目录url路径。
 只能在web访问时使用,在命令行下面会抛出异常。
 *
 * @param type $subpath 子路径或者文件路径,如果非空就会被附加在入口文件所在目录的后面
 * @return type
 * @throws Exception
 */
 public static function urlPath($subpath = null)
 {
     if (CoreInput::isCli()) {
         throw new Exception('function urlPath() can not be used in cli mode');
     } else {
         $old_path = getcwd();
         $root = str_replace(array('/', '\\'), '/', CoreInput::server('DOCUMENT_ROOT'));
         chdir($root);
         $root = getcwd();
         $root = str_replace(array('/', '\\'), '/', $root);
         chdir($old_path);
         $path = self::path($subpath);
         return str_replace($root, '', $path);
     }
 }
コード例 #3
0
ファイル: Router.php プロジェクト: admpub/MicroPHP
 private static function checkSession()
 {
     $system = CoreLoader::$system;
     $common_config = $system['session_handle']['common'];
     ini_set('session.auto_start', 0);
     ini_set('session.gc_probability', 1);
     ini_set('session.gc_divisor', 100);
     ini_set('session.gc_maxlifetime', $common_config['lifetime']);
     ini_set('session.referer_check', '');
     ini_set('session.entropy_file', '/dev/urandom');
     ini_set('session.entropy_length', 16);
     ini_set('session.use_cookies', 1);
     ini_set('session.use_only_cookies', 1);
     ini_set('session.use_trans_sid', 0);
     ini_set('session.hash_function', 1);
     ini_set('session.hash_bits_per_character', 5);
     session_cache_limiter('nocache');
     session_set_cookie_params($common_config['lifetime'], $common_config['cookie_path'], preg_match('/^[^\\.]+$/', CoreInput::server('HTTP_HOST')) ? null : $common_config['cookie_domain']);
     session_name($common_config['session_name']);
     register_shutdown_function('session_write_close');
     if (!empty($system['session_handle']['handle']) && isset($system['session_handle'][$system['session_handle']['handle']])) {
         $driver = $system['session_handle']['handle'];
         $config = $system['session_handle'];
         $handle = ucfirst($driver) . 'SessionHandle';
         if (class_exists($handle, FALSE)) {
             $session = new $handle();
             $session->start($config);
         }
     }
     if ($common_config['autostart']) {
         sessionStart();
     }
 }