Changeset 56

Show
Ignore:
Timestamp:
02/06/08 12:12:46 (3 months ago)
Author:
gerd
Message:

Allow to set cookie parameter

  • this fixes a bug using token-cookies as well as multiple URLs
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/patSession/Storage.php

    r49 r56  
    55 * $Id$ 
    66 * 
    7  * @version     2.2.0 
     7 * @version     2.3.0 
    88 * @package patSession 
    99 * @subpackage Storage 
     
    158158        final public function __construct( $id = 'session', $options = array() ) 
    159159        { 
     160        // extract default cookie parameter    
     161        $this->_cookieParams    =   session_get_cookie_params(); 
     162         
    160163                $this->_id      =       $id; 
    161164                $this->_setOptions( $options ); 
     
    808811        // try to set a cookie           
    809812        if( $this->_tokenMode == 'any' || $this->_tokenMode == 'cookie' ) { 
    810             setcookie( $this->_tokenName, $tokenNew ); 
     813            setcookie( $this->_tokenName, $tokenNew, $this->_cookieParams['lifetime'], $this->_cookieParams['path'] ); 
    811814        } 
    812815             
     
    815818            return true; 
    816819        } 
    817                  
    818         $match  =   false; 
    819          
     820 
    820821        // check token from cookie 
    821822        if( ( $this->_tokenMode == 'any' || $this->_tokenMode == 'cookie' ) && isset( $_COOKIE[$this->_tokenName] ) && $_COOKIE[$this->_tokenName] == $token ) { 
    822             $match  =  true; 
     823            return true; 
    823824        } 
    824825             
    825826        // check token send as get parameter 
    826827        if( ( $this->_tokenMode == 'any' || $this->_tokenMode == 'get' ) && isset( $_GET[$token] ) ) { 
    827             $match  =   true; 
    828         } 
    829          
    830         if( $match ) { 
    831828            return true; 
    832829        } 
     
    917914                        $this->_emptyReferer    =       'allow'; 
    918915                } 
     916         
     917        // cookie options 
     918        foreach( $this->_cookieParams as $k => &$v ) { 
     919            if( isset( $options['cookie_' . $k] ) ) { 
     920                $v  =   $options['cookie_' . $k]; 
     921            } 
     922        } 
    919923                 
    920924                return true; 
  • trunk/patSession/Storage/Native.php

    r46 r56  
    5252    protected function _start() 
    5353    { 
     54        session_set_cookie_params( $this->_cookieParams['lifetime'] 
     55                                  , $this->_cookieParams['path'] 
     56                                  , $this->_cookieParams['domain'] 
     57                                  , $this->_cookieParams['secure'] 
     58                                ); 
     59     
    5460                //  start session if not startet 
    5561                if( $this->_state != 'restart' && !defined( 'SID' ) ) { 
     
    121127                        ini_set( 'session.use_trans_sid', 0 ); 
    122128                } 
    123                 $cookie =       session_get_cookie_params(); 
    124  
    125                 // create new session id                 
     129         
     130                // create new session id 
    126131                $id     =       $this->_createId(); 
    127132                 
     
    131136                // restore config                
    132137                ini_set( 'session.use_trans_sid', $trans ); 
    133                 session_set_cookie_params( $cookie['lifetime'], $cookie['path'], $cookie['domain'], $cookie['secure'] ); 
     138                session_set_cookie_params( $this->_cookieParams['lifetime'] 
     139                                  , $this->_cookieParams['path'] 
     140                                  , $this->_cookieParams['domain'] 
     141                                  , $this->_cookieParams['secure'] 
     142                                ); 
    134143                 
    135144                // restart session with new id