Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Not an Issue
-
Affects Version/s: 1.0.0
-
Fix Version/s: Next Major Release
-
Component/s: Zend_Session
-
Labels:None
-
Fix Version Priority:Should Have
Description
If you try to use Zend_Session setId to restablish a session inside of a PHP CLI script, you get hit by one or two errors:
The session has already been started. The session id must be set first.
Also if your script happens to output anything to the screen:
You must call Zend_Session::setId() before any output has been sent to the browser; output started in
(This shouldn't matter because you're using a CLI so headers has no bearing on anything. There should be a way to override this check)
The code I am using is as simple as:
Zend_Session::setId($input['TOKEN']); Zend_Session::start();
It makes no difference if I call Zend_Session::destroy() prior to this. The code above works fine from CLI using Zend_XMLRpc, but it won't work if I call the functions directly from my own CLI script.
Although I don't know all the ramifications, etc., but one easy solution I might suggest is to add an IF statement around the first two checks, like this:
if (php_sapi_name() != 'cli')
{
if (defined('SID')) { throw new Zend_Session_Exception('The session has already been started. The session id must be set first.'); }
if (headers_sent($filename, $linenum)) {
throw new Zend_Session_Exception("You must call "._CLASS.'::'.FUNCTION_.
"() before any output has been sent to the browser; output started in {$filename}/{$linenum}");
}
}