Hi there everyone,
I moved a Post Nuke site from a PHP4 environment to a server with PHP5. When I did that, the site was broken due to the session function not working on the new server. Through searching, I found a fix posted on the forum:
Original session function:
function pnSessionSetup()
{
$path = pnGetBaseURI();
if (empty($path)) {
$path = '/';
}
$host = pnServerGetVar('HTTP_HOST');
// itevo
if (strpos($host, ':') !== false) {
$host = substr($host,0, strpos($host, ':'));
}
// PHP configuration variables
// Stop adding SID to URLs
ini_set('session.use_trans_sid', 0);
ini_set('url_rewriter.tags', '');
// User-defined save handler
ini_set('session.save_handler', 'user');
// How to store data
ini_set('session.serialize_handler', 'php');
// Use cookie to store the session ID
ini_set('session.use_cookies', 1);
// Name of our cookie
ini_set('session.name', 'POSTNUKESID');
// Lifetime of our cookie
$seclevel = pnConfigGetVar('seclevel');
switch ($seclevel) {
case 'High':
// Session lasts duration of browser
$lifetime = 0;
// Referer check
// ini_set('session.referer_check', "$host$path");
ini_set('session.referer_check', "$host");
break;
case 'Medium':
// Session lasts set number of days
$lifetime = pnConfigGetVar('secmeddays') * 86400;
break;
case 'Low':
default :
// Session lasts unlimited number of days (well, lots, anyway)
// (Currently set to 25 years)
$lifetime = 788940000;
break;
}
ini_set('session.cookie_lifetime', $lifetime);
// if (pnConfigGetVar('intranet') == false) {
// Cookie path
ini_set('session.cookie_path', $path);
// Cookie domain
// only needed for multi-server multisites - adapt as needed
// $domain = preg_replace('/^[^.]+/','',$host);
// ini_set('session.cookie_domain', $domain);
// }
// Garbage collection
ini_set('session.gc_probability', 1);
// Inactivity timeout for user sessions
ini_set('session.gc_maxlifetime', pnConfigGetVar('secinactivemins') * 60);
// Auto-start session
ini_set('session.auto_start', 1);
// Session handlers
session_set_save_handler('pnSessionOpen',
'pnSessionClose',
'pnSessionRead',
'pnSessionWrite',
'pnSessionDestroy',
'pnSessionGC');
return true;
}
Which allowed a page to load, but nobody could log in and caused the following error on the site:
PHP Fatal error: Call to a member function Execute() on a non-object in /home/site/public_html/includes/pnSession.php on line 378.
The fix I found modified the session function by adding one line:
register_shutdown_function('session_write_close');
To make the end of the function look like this:
register_shutdown_function('session_write_close');
session_set_save_handler('pnSessionOpen',
'pnSessionClose',
'pnSessionRead',
'pnSessionWrite',
'pnSessionDestroy',
'pnSessionGC');
return true;
}
To Help: The seclevel is set to "Low" in the config.
Now, people can log in. The problem I have now is that there is no longer a long term session and people have to keep logging in over the period of the visit. They'll be logged in until they either shut the browser or until they are inactive for a period of time. If they keep browsing, it seems to keep them logged in.
My question is this: Is there something I can do to get the function working again? The fix posted on the PostNuke site did get rid of the error, but it's not truly a fix, but instead just a band-aid.
thanks,
json