Jump to content

session_set_save_handler


glenelkins

Recommended Posts

Hi

 

Just a quick one, can anyone see what im doing wrong here, the _write function doesnt seem to send anything to the database( please note iv never used this function in the past so im learning it )

 

Sesssions.class.php

<?php

class Sessions {

var $registry;

private $__dbTable = 'php_session';

function __construct ( $registry ) {

	$this->registry = $registry;

}

public function _open ( $save_path, $session_name ) {

	// do nothing, we are using database

	return true;

}

public function _close () {

	return true;

}

public function _read() {

}

public function _write( $session_id, $session_data ) {

	// Check to see if the sesison already exists
	$res = $this->registry->db->fquery ( "SELECT * FROM `{$this->$__dbTable}` WHERE `session_id` = '$session_id'" );

	if ( $res->fnum_rows() ) {

		// Exists, so update
		$this->registry->db->fquery ( "UPDATE `{$this->$__dbTable}` SET 
										`session_data` = '$session_data',
										`last_update` = '" . date ( "Y-m-d H:i:s", time() ) . "'

									WHERE `session_id` = '$session_id');" );

	} else {


		$this->registry->db->fquery ( "INSERT INTO `sessions` VALUES (
										'$session_id',
										'',
										'" . date ( "Y-m-d H:i:s", time() ) . "',
										'" . date ( "Y-m-d H:i:s", time() ) . "',
										'$session_data'
										);" );

	}

}

public function _destroy() {

}

public function _garbage() {

}


}

?>

 

init.php

$registry->sessions = new Sessions ( $registry );

// Create the session handler and start the session
session_set_save_handler ( 
array ( $registry->sessions, '_open' ),
array ( $registry->sessions, '_close' ),
array ( $registry->sessions, '_read' ),
array ( $registry->sessions, '_write' ),
array ( $registry->sessions, '_destroy' ),
array ( $registry->sessions, '_garbage' )
);

$_SESSION['test'] = 'HEllo';

Link to comment
https://forums.phpfreaks.com/topic/167097-session_set_save_handler/
Share on other sites

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.