Home : Products : Gossamer Links : PHP Front End :

Products: Gossamer Links: PHP Front End: Help with class and object errors anyone?: Edit Log

Here is the list of edits for this post
Help with class and object errors anyone?

Can anyone help me out with this small session class I'm playing with. The below class is included into a file and then called with...

$SN = new Session;

class Session {

function Session () {
$this->session_name = 'sessi0n';
$this->session_data = array();
$this->session_user_id = 'test';

function start_session () {
global $DB ;

# If we don't already have an open session via cookie
if (! $_COOKIE["$this->session_name"] ) {

$this->session_id = md5( microtime() );
$this->session_date = time() ;

$session = get_object_vars($this);
$info = var_export($session, true);

$ret = $DB->insert("Sessions", $info );


When I run the above with the line "$ret = $DB->insert("Sessions", $info );" commented OUT it gives the following error notice in my log file:

[error] PHP Notice: Undefined index: sessi0n in /path/to/session.class.php on line XX (referring to $_COOKIE["$this->session_name"]). Do you know how to fix this error?

If I uncomment the line "$ret = $DB->insert("Sessions", $info );" it also returns the following error...

[Sun Nov 6 11:23:58 2005] [error] PHP Fatal error: Call to a member function on a non-object in /path/to/session.class.php on line XX referring to "$ret = $DB->insert("Sessions", $info );" - which I assume means it doesn't know about the $DB object that I'm trying to use. That DB object was created just before the session object so it does already exist.

Can anyone help?



Last edited by:

ryel01: Nov 5, 2005, 2:30 PM

Edit Log: