CrossPHP
  • Namespace
  • Class
  • Download

Namespaces

  • Cross
    • Auth
    • Cache
      • Driver
      • Request
    • Core
    • DB
      • Connecter
      • Drivers
      • SQLAssembler
    • Exception
    • Http
    • I
    • Lib
      • Document
    • Module
    • MVC
    • Runtime
  • None

Classes

  • Cross\Auth\CookieAuth
  • Cross\Auth\SessionAuth
  • Cross\Cache\Driver\FileCacheDriver
  • Cross\Cache\Driver\MemcacheDriver
  • Cross\Cache\Driver\RedisDriver
  • Cross\Cache\Request\FileCache
  • Cross\Cache\Request\Memcache
  • Cross\Cache\Request\RedisCache
  • Cross\Cache\RequestCache
  • Cross\Core\Annotate
  • Cross\Core\Application
  • Cross\Core\ArrayMap
  • Cross\Core\Config
  • Cross\Core\CrossArray
  • Cross\Core\Delegate
  • Cross\Core\FrameBase
  • Cross\Core\Helper
  • Cross\Core\HttpAuth
  • Cross\Core\Loader
  • Cross\Core\Rest
  • Cross\Core\Router
  • Cross\DB\Connecter\BaseConnecter
  • Cross\DB\Connecter\MySQLConnecter
  • Cross\DB\Connecter\PgSQLConnecter
  • Cross\DB\Connecter\SQLiteConnecter
  • Cross\DB\DBFactory
  • Cross\DB\Drivers\CouchDriver
  • Cross\DB\Drivers\MongoDriver
  • Cross\DB\Drivers\PDOSqlDriver
  • Cross\DB\SQLAssembler\MySQLAssembler
  • Cross\DB\SQLAssembler\PgSQLAssembler
  • Cross\DB\SQLAssembler\SQLAssembler
  • Cross\DB\SQLAssembler\SQLiteAssembler
  • Cross\Http\Request
  • Cross\Http\Response
  • Cross\Lib\Array2XML
  • Cross\Lib\Document\CallTree
  • Cross\Lib\Document\CallTreeToHTML
  • Cross\Lib\Document\HTML
  • Cross\Lib\StringToPHPStream
  • Cross\Module\SQLModule
  • Cross\MVC\Controller
  • Cross\MVC\Module
  • Cross\MVC\View
  • Cross\Runtime\ClosureContainer

Interfaces

  • Cross\I\CacheInterface
  • Cross\I\HttpAuthInterface
  • Cross\I\PDOConnecter
  • Cross\I\RequestCacheInterface
  • Cross\I\RouterInterface
  • Cross\I\SqlInterface

Exceptions

  • Cross\Exception\CacheException
  • Cross\Exception\CoreException
  • Cross\Exception\CrossException
  • Cross\Exception\FrontException

Functions

  • ascLogo
  • line
  • tBody
  • th
  • tHead
 1 <?php
 2 /**
 3  * Cross - a micro PHP 5 framework
 4  *
 5  * @link        http://www.crossphp.com
 6  * @license     MIT License
 7  */
 8 namespace Cross\Auth;
 9 
10 use Cross\I\HttpAuthInterface;
11 
12 /**
13  * @author wonli <wonli@live.com>
14  * Class SessionAuth
15  * @package Cross\Auth
16  */
17 class SessionAuth implements HttpAuthInterface
18 {
19     /**
20      * 加解密默认key
21      *
22      * @var string
23      */
24     protected $key;
25 
26     function __construct($key = '')
27     {
28         if ($key) {
29             $this->key = $key;
30         }
31 
32         if (!isset($_SESSION)) {
33             session_start();
34         }
35     }
36 
37     /**
38      * 设置session的值
39      *
40      * @param string $key
41      * @param string|array $value
42      * @param int $expire
43      * @return bool|mixed
44      */
45     function set($key, $value, $expire = 0)
46     {
47         if (is_array($value)) {
48             $value = json_encode($value);
49         }
50 
51         $_SESSION[$key] = $value;
52         return true;
53     }
54 
55     /**
56      * 获取session的值
57      *
58      * @param string $key
59      * @param bool $deCode
60      * @return bool|mixed
61      */
62     function get($key, $deCode = false)
63     {
64         if (false !== strpos($key, ':') && $deCode) {
65             list($key, $arrKey) = explode(':', $key);
66         }
67 
68         if (!isset($_SESSION[$key])) {
69             return false;
70         }
71 
72         $result = $_SESSION[$key];
73         if ($deCode) {
74             $result = json_decode($result, true);
75             if (isset($arrKey) && isset($result[$arrKey])) {
76                 return $result[$arrKey];
77             }
78         }
79 
80         return $result;
81     }
82 }
83 
CrossPHP API documentation generated by ApiGen