Skip to content

Commit

Permalink
Fix #10187: Segment the PHP session via a unique key, so as to play n…
Browse files Browse the repository at this point in the history
…ice with neighboring apps.
  • Loading branch information
amyreese committed Mar 30, 2009
1 parent da55110 commit 2ad35dd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
6 changes: 6 additions & 0 deletions config_defaults_inc.php
Expand Up @@ -219,6 +219,12 @@
*/
$g_session_handler = 'php';

/**
* Session key name. Should be unique between multiple installations to prevent conflicts.
* @global string $g_session_key
*/
$g_session_key = 'MantisBT';

/**
* Session save path. If false, uses default value as set by session handler.
* @global bool $g_session_save_path
Expand Down
24 changes: 17 additions & 7 deletions core/session_api.php
Expand Up @@ -52,29 +52,40 @@ abstract function destroy();
*/
class MantisPHPSession extends MantisSession {
function __construct( $p_session_id=null ) {
$this->key = config_get_global( 'session_key' );

# Save session information where specified or with PHP's default
$t_session_save_path = config_get_global( 'session_save_path' );
if( $t_session_save_path ) {
session_save_path( $t_session_save_path );
}

# Handle session cookie and caching
session_cache_limiter( 'private_no_expire' );
if ( isset( $_SERVER['HTTPS'] ) && ( strtolower( $_SERVER['HTTPS'] ) != 'off' ) ) {
session_set_cookie_params( 0, config_get( 'cookie_path' ), config_get( 'cookie_domain' ), true );
} else {
session_set_cookie_params( 0, config_get( 'cookie_path' ), config_get( 'cookie_domain' ), false );
}

# Handle existent session ID
if ( !is_null( $p_session_id ) ) {
session_id( $p_session_id );
}

# Initialize the session
session_start();
$this->id = session_id();

# Initialize the keyed session store
if ( !isset( $_SESSION[ $this->key ] ) ) {
$_SESSION[ $this->key ] = array();
}
}

function get( $p_name, $p_default = null ) {
if( isset( $_SESSION[$p_name] ) ) {
return unserialize( $_SESSION[$p_name] );
function get( $p_name, $p_default=null ) {
if ( isset( $_SESSION[ $this->key ][ $p_name ] ) ) {
return unserialize( $_SESSION[ $this->key ][ $p_name ] );
}

if( func_num_args() > 1 ) {
Expand All @@ -86,20 +97,19 @@ function get( $p_name, $p_default = null ) {
}

function set( $p_name, $p_value ) {
$_SESSION[$p_name] = serialize( $p_value );
$_SESSION[ $this->key ][ $p_name ] = serialize( $p_value );
}

function delete( $p_name ) {
unset( $_SESSION[$p_name] );
unset( $_SESSION[ $this->key ][ $p_name ] );
}

function destroy() {
if( isset( $_COOKIE[session_name()] ) && !headers_sent() ) {
gpc_set_cookie( session_name(), '', time() - 42000 );
}

unset( $_SESSION );
session_destroy();
unset( $_SESSION[ $this->key ] );
}
}

Expand Down

0 comments on commit 2ad35dd

Please sign in to comment.