Jump to content

[SOLVED] Two Session Paths?


fanfavorite

Recommended Posts

I have an extremely large program that uses two session variables.  Both which are declared $_SESSION[sessionname] = "Some Value" on PHP 5.2.2.  Now I am trying to integrate an outside program with it that uses a custom session handler.  Now they say that the problem of me using their custom session handler is the path of the session. 

 

$_SESSION[1] = Value 1; //Declared in /login

$_SESSION[2] = Value 2; //Declared in / 

New Script //Declared in /folder/admin/temp

 

I have used $_SESSION[1] and $_SESSION[2] in many directories, etc.  In the PHP info, the session.save_path has no value, I have tried changing this, but doesn't seem to do anything different. 

 

If I blow away the session handler for the new program and call session_start(); then the sessions will display, however I am unable to do this because the sessions of the program don't work. 

 

Anyways, my question is, can I set the session to path root and also path folder/admin/temp so that it is available throughout a domain, but also is specific for this program? 

 

If you have any other ideas, please let me know. 

 

Thanks,

 

-JC

Link to comment
https://forums.phpfreaks.com/topic/108844-solved-two-session-paths/
Share on other sites

session.save_path string

session.save_path defines the argument which is passed to the save handler. If you choose the default files handler, this is the path where the files are created.

 

session.cookie_path string

session.cookie_path specifies path to set in session_cookie. Defaults to /.

 

The session save path is where the session data files are stored. This has nothing to do with the path to the script file where a session is started/resumed.

 

Any custom session handler that is written properly will simply replace the built in files handler using a call to the session_set_save_handler() function and sessions will continue to work using all the standard built in methods (session_start(), $_SESSION['your_variable'] = 'your_value';...) Php uses the session.cookie_path setting when it sends the session cookie and that actually has nothing to do with the session handler functions.

 

You would need to provide more information about what the script using the custom session handler is and what it is doing.

Thanks for the help.  The session handler is:

 

class Session {
var $SessionName = 'SomeSession';
var $_ExternalVars = array();
function Session($SessionName='') {
	if ($SessionName) {
		$this->SessionName = $SessionName;
	}
	return true;
}
function Set($var='', $val='')	{
	if ($var == '') {
		return false;
	}
	$this->_ExternalVars[$var] = $val;
	return true;
}

function Get($var='') {
	if ($var == '') {
		return false;
	}

	if (!isset($this->_ExternalVars[$var])) {
		return false;
	}

	return $this->_ExternalVars[$var];
}
}

if (!defined('CRON_JOB') && !defined('NO_SESSION')) {
if (is_writable(TEMP_DIRECTORY)) {
	ini_set('session.save_handler', 'files');
	if (defined('TEMP_DIRECTORY')) {
		ini_set('session.save_path', TEMP_DIRECTORY);
	}
}
ini_set('session.use_cookies',1);
ini_set('session.gc_probability', 1);
ini_set('session.gc_divisor', 100);
ini_set('session.gc_maxlifetime', 3600);
session_start();
}

I was told by support to use:

 

$session = GetSession();
$value1 = $session->Get('1');
$value2 = $session->Get('2');

 

But nothing comes up. 

That is actually not a custom session handler. It is a session data management class (assuming it creates the object in a session and you posted all of what it is doing.)

 

For the same session data to be available on any page on a site, all the scripts on that site must use the same session session.save_path.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.