Changeset 1779

Show
Ignore:
Timestamp:
01/21/2008 01:34:23 PM (12 months ago)
Author:
Geert
Message:
  • Session names should only contain alphanumeric characters with at least one letter (check the manual: http://php.net/session_name). This is now required, otherwise a session.invalid_session_name exception will be thrown. Translators!
  • The httponly parameter of the session_set_cookie_params() function is only supported by PHP 5.2 and up. Built in a version check.
  • Kohana::$user_agent is now set by the user_agent() method of the Input library.
Location:
trunk/system
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/config/session.php

    r1753 r1779  
    1414/** 
    1515 * Default session name. 
     16 * It should contain only alphanumeric characters and at least one letter should be present. 
    1617 */ 
    17 $config['name'] = 'kohana_session'; 
     18$config['name'] = 'kohanasession'; 
    1819 
    1920/** 
  • trunk/system/core/Kohana.php

    r1773 r1779  
    5555                $ER = error_reporting(0); 
    5656 
    57                 // Set the user agent 
    58                 self::$user_agent = trim($_SERVER['HTTP_USER_AGENT']); 
    59  
    6057                if (function_exists('date_default_timezone_set')) 
    6158                { 
     
    10097                // Set locale information 
    10198                setlocale(LC_ALL, Config::item('locale.language').'.UTF-8'); 
     99 
     100                // Set the user agent 
     101                self::$user_agent = Input::instance()->user_agent(); 
    102102 
    103103                // Enable Kohana routing 
  • trunk/system/i18n/en_US/session.php

    r1772 r1779  
    55        'no_table'                        => 'The configured session table, %s, was not found.', 
    66        'driver_not_supported'            => 'The requested Session driver, %s, was not found.', 
    7         'driver_must_implement_interface' => 'Session drivers must implement the Session_Driver interface.' 
     7        'driver_must_implement_interface' => 'Session drivers must implement the Session_Driver interface.', 
     8        'invalid_session_name'            => 'The session_name, %s, is invalid. It should contain only alphanumeric characters and at least one letter should be present.', 
    89); 
  • trunk/system/i18n/nl_NL/session.php

    r1524 r1779  
    55        'no_table'                        => 'De session tabel, %s, werd niet gevonden.', 
    66        'driver_not_supported'            => 'De opgevraagde session driver, %s, werd niet gevonden.', 
    7         'driver_must_implement_interface' => 'Session drivers moeten de Session_Driver interface implementeren.' 
     7        'driver_must_implement_interface' => 'Session drivers moeten de Session_Driver interface implementeren.', 
     8        'invalid_session_name'            => 'De session naam, %s, is ongeldig. Hij mag alleen maar bestaan uit alfanumerieke karakters en moet minstens één letter bevatten.', 
    89); 
  • trunk/system/libraries/Input.php

    r1754 r1779  
    318318                        return $this->user_agent; 
    319319 
    320                 $this->user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : FALSE; 
     320                $this->user_agent = (isset($_SERVER['HTTP_USER_AGENT'])) ? trim($_SERVER['HTTP_USER_AGENT']) : FALSE; 
    321321 
    322322                return $this->user_agent; 
  • trunk/system/libraries/Session.php

    r1773 r1779  
    119119 
    120120                // Set the session cookie parameters 
    121                 session_set_cookie_params 
    122                 ( 
    123                         self::$config['expiration'], 
    124                         Config::item('cookie.path'), 
    125                         Config::item('cookie.domain'), 
    126                         Config::item('cookie.secure'), 
    127                         Config::item('cookie.httponly') 
    128                 ); 
     121                // Note: the httponly parameter was added in PHP 5.2.0 
     122                if (version_compare(PHP_VERSION, '5.2.0', '>=')) 
     123                { 
     124                        session_set_cookie_params 
     125                        ( 
     126                                self::$config['expiration'], 
     127                                Config::item('cookie.path'), 
     128                                Config::item('cookie.domain'), 
     129                                Config::item('cookie.secure'), 
     130                                Config::item('cookie.httponly') 
     131                        ); 
     132                } 
     133                else 
     134                { 
     135                        session_set_cookie_params 
     136                        ( 
     137                                self::$config['expiration'], 
     138                                Config::item('cookie.path'), 
     139                                Config::item('cookie.domain'), 
     140                                Config::item('cookie.secure') 
     141                        ); 
     142                } 
    129143 
    130144                if (self::$config['driver'] != 'native') 
     
    142156                } 
    143157 
    144                 // Set the session name 
     158                // Set the session name after having checked it 
     159                if ( ! ctype_alnum(self::$config['name']) OR ctype_digit(self::$config['name'])) 
     160                        throw new Kohana_Exception('session.invalid_session_name', self::$config['name']); 
     161 
    145162                session_name(self::$config['name']); 
    146163 
     
    154171                if ( ! isset($_SESSION['_kf_flash_'])) 
    155172                { 
    156                         $_SESSION['user_agent'] = Kohana::$user_agent; 
     173                        $_SESSION['user_agent'] = $this->input->user_agent(); 
    157174                        $_SESSION['ip_address'] = $this->input->ip_address(); 
    158175                        $_SESSION['_kf_flash_'] = array(); 
     
    179196                                                if ($_SESSION[$valid] !== $this->input->$valid()) 
    180197                                                { 
    181                                                         session_unset(); 
    182198                                                        return $this->create(); 
    183199                                                } 
     
    225241                { 
    226242                        // Pass the regenerating off to the driver in case it wants to do anything special 
    227                         // The new id is returned 
    228243                        $_SESSION['session_id'] = self::$driver->regenerate(); 
    229244                } 
     
    244259                        session_unset(); 
    245260 
    246                         // Write the session 
     261                        // Destroy the session 
    247262                        return session_destroy(); 
    248263                } 
     
    287302        public function set_flash($keys, $val = FALSE) 
    288303        { 
    289                 if ($keys == FALSE) 
    290                         return; 
     304                if (empty($keys)) 
     305                        return FALSE; 
    291306 
    292307                if ( ! is_array($keys)) 
     
    336351        public function get($key = FALSE, $default = FALSE) 
    337352        { 
    338                 if ($key == FALSE) 
     353                if (empty($key)) 
    339354                        return $_SESSION; 
    340355 
    341                 $result = isset($_SESSION[$key]) ? $_SESSION[$key] : Kohana::key_string($key, $_SESSION); 
     356                $result = (isset($_SESSION[$key])) ? $_SESSION[$key] : Kohana::key_string($key, $_SESSION); 
    342357 
    343358                return ($result === NULL) ? $default : $result; 
     
    381396                foreach((array) $keys as $key) 
    382397                { 
    383                         if(isset(self::$protect[$key])) 
     398                        if (isset(self::$protect[$key])) 
    384399                                continue; 
    385400