I extended the CDbHttpSession class to store a little more info on the session data so here’s my mod:
class WB_CDbHttpSession extends CDbHttpSession {
public function writeSession ( $id, $data )
{
$expire = time () + $this->getTimeout ();
$id = md5 ( $id );
$db = $this->getDbConnection ();
$sql = "SELECT id FROM {$this->sessionTableName} WHERE id='$id'";
if ( $db->createCommand ( $sql )->queryScalar () === false ) {
$sql = "INSERT INTO {$this->sessionTableName} (id, data, expire, username, user_id, last_page, user_ip) VALUES ('$id', :data, $expire, :username, :user_id, :last_page, :user_ip)";
}
else {
$sql = "UPDATE {$this->sessionTableName} SET expire=$expire, data=:data WHERE id='$id'";
}
$command = $db->createCommand ( $sql );
$command->bindParam ( ':data', $data );
$username = wb_user ()->getName ();
$userId = wb_user ()->getId ();
$url = wb_request ()->requestUri;
$ip = WB_VisitorInfo::ip ( true );
$command->bindParam ( ':username', $username );
$command->bindParam ( ':user_id', $userId );
$command->bindParam ( ':last_page', $url );
$command->bindParam ( ':user_ip', $ip );
$command->execute ();
return true;
}
}
The only problem with is that I have an error being printed on my footer:
Exception thrown without a stack frame in Unknown on line 0
If I change the code to this unsafe method it works perfectly:
class WB_CDbHttpSession extends CDbHttpSession {
public function writeSession ( $id, $data )
{
$expire = time () + $this->getTimeout ();
$id = md5 ( $id );
$db = $this->getDbConnection ();
$sql = "SELECT id FROM {$this->sessionTableName} WHERE id='$id'";
if ( $db->createCommand ( $sql )->queryScalar () === false ) {
$sql = "INSERT INTO {$this->sessionTableName} (id, data, expire, username, user_id, last_page, user_ip) VALUES ('$id', :data, $expire, '" . wb_user ()->getName () . "', '" . wb_user ()->getId () . "', '" . wb_request ()->requestUri . "', '" . WB_VisitorInfo::ip ( true ) . "')";
}
else {
$sql = "UPDATE {$this->sessionTableName} SET expire=$expire, data=:data WHERE id='$id'";
}
$command = $db->createCommand ( $sql );
$command->bindParam ( ':data', $data );
$command->execute ();
return true;
}
}
Any ideas?