KCfinder gebruikt de file "autoload.php" waar een voorbeeld in staat.
Onze website gebruiker de file "session.php".
Het comment blok in autoload.php zal geactiveerd moeten worden maar wat dan nog meer. Op een of andere manier moeten ze toch naar elkaar verwijzen lijkt mij?
autoload.php
// CUSTOM SESSION SAVE HANDLER CLASS EXAMPLE
//
// Uncomment & edit it if the application you want to integrate with, have
// its own session save handler. It's not even needed to save instances of
// this class in variables. Just add a row:
// new SessionSaveHandler();
// and your handler will rule the sessions ;-)
/*
class SessionSaveHandler {
protected $savePath;
protected $sessionName;
public function __construct() {
session_set_save_handler(
array($this, "open"),
array($this, "close"),
array($this, "read"),
array($this, "write"),
array($this, "destroy"),
array($this, "gc")
);
}
// Open function, this works like a constructor in classes and is
// executed when the session is being opened. The open function expects
// two parameters, where the first is the save path and the second is the
// session name.
public function open($savePath, $sessionName) {
$this->savePath = $savePath;
$this->sessionName = $sessionName;
return true;
}
// Close function, this works like a destructor in classes and is
// executed when the session operation is done.
public function close() {
return true;
}
// Read function must return string value always to make save handler
// work as expected. Return empty string if there is no data to read.
// Return values from other handlers are converted to boolean expression.
// TRUE for success, FALSE for failure.
public function read($id) {
$file = $this->savePath . "/sess_$id";
return (string) @file_get_contents($file);
}
// Write function that is called when session data is to be saved. This
// function expects two parameters: an identifier and the data associated
// with it.
public function write($id, $data) {
$file = $this->savePath . "/sess_$id";
if (false !== ($fp = @fopen($file, "w"))) {
$return = fwrite($fp, $data);
fclose($fp);
return $return;
} else
return false;
}
// The destroy handler, this is executed when a session is destroyed with
// session_destroy() and takes the session id as its only parameter.
public function destroy($id) {
$file = $this->savePath . "/sess_$id";
return @unlink($file);
}
// The garbage collector, this is executed when the session garbage
// collector is executed and takes the max session lifetime as its only
// parameter.
public function gc($maxlifetime) {
foreach (glob($this->savePath . "/sess_*") as $file)
if (filemtime($file) + $maxlifetime < time())
@unlink($file);
return true;
}
}
new SessionSaveHandler();
*/
session.php
/* Create new object of class */
$ses_class = new session();
$ses_class->ses_table = $dbprefix . "sessions";
/* Change the save_handler to use the class functions */
session_set_save_handler(array (
& $ses_class,
'_open'
), array (
& $ses_class,
'_close'
), array (
& $ses_class,
'_read'
), array (
& $ses_class,
'_write'
), array (
& $ses_class,
'_destroy'
), array (
& $ses_class,
'_gc'
));
/* Start the session */
session_start();
class session
{
/* Define the mysql table you wish to use with
this class, this table MUST exist. */
var $ses_table;
/* Open session */
function _open($path, $name)
{
/* just define this function. */
return TRUE;
}
/* Close session */
function _close()
{
/* This is used for a manual call of the
session gc function */
$this->_gc(0);
return TRUE;
}
/* Read session data from database */
function _read($ses_id)
{
$session_sql = "SELECT * FROM " . $this->ses_table . " WHERE ses_id = '$ses_id'";
$session_res = @ mysql_query($session_sql);
if (!$session_res)
{
return '';
}
$session_num = @ mysql_num_rows($session_res);
if ($session_num > 0)
{
$session_row = mysql_fetch_assoc($session_res);
$ses_data = $session_row["ses_value"];
return $ses_data;
}
else
{
return '';
}
}
/* Write new data to database */
function _write($ses_id, $data)
{
$session_sql = "UPDATE " . $this->ses_table . " SET ses_time='" . time() . "', ses_value='$data' WHERE ses_id='$ses_id'";
$session_res = @ mysql_query($session_sql);
if (!$session_res)
{
return FALSE;
}
if (mysql_affected_rows())
{
return TRUE;
}
$session_sql = "INSERT INTO " . $this->ses_table . " (ses_id, ses_time, ses_start, ses_value)" . " VALUES ('$ses_id', '" . time() . "', '" . time() . "', '$data')";
$session_res = @ mysql_query($session_sql);
if (!$session_res)
{
return FALSE;
}
else
{
return TRUE;
}
}
/* Destroy session record in database */
function _destroy($ses_id)
{
$session_sql = "DELETE FROM " . $this->ses_table . " WHERE ses_id = '$ses_id'";
$session_res = @ mysql_query($session_sql);
if (!$session_res)
{
return FALSE;
}
else
{
return TRUE;
}
}
/* Garbage collection, deletes old sessions */
function _gc($life)
{
$ses_life = strtotime("-60 minutes");
$session_sql = "DELETE FROM " . $this->ses_table . " WHERE ses_time < $ses_life";
$session_res = @ mysql_query($session_sql);
if (!$session_res)
{
return FALSE;
}
else
{
return TRUE;
}
}
}