voor het toevoegen van foto's probeer ik KCfinder te intergreren. Maar omdat onze bestaande website de sessie wegschrijft naar een database wil dat niet lukken. De handleiding zegt dat we de "session save handler" moeten intergreren. Maar hoe.
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;
}
}
}
Google werkt vrij goed moet ik zeggen.

Officiele documentatie van kcfinder in session save handler intergratie.link

P.S. letterlijk de eerste link op Google.
Dat is inderdaad de handleiding en daarin staat:
IMPORTANT NOTE: If you have session.save_handler with local value "user", your application uses its own session save handler. You need to implement the same handler using session_set_save_handler() function in core/autoload.php file which contains an example handler class.


Omdat wij dus blijkbaar een eigen session save handler hebben zullen we wat moeten doen met die handler. Moet ik dan de complete session.php van de originele website copieren in de autoload.php van KCfinder?
Heb je de documentatie doorgelezen?

Ook in je quote zie je dat je in de autoloader dezelfde parameter moet gebruiken als in je eigen sessie. Dat doe je met session_set_save_handler().

Op de site zijn dit klikbare linkjes, dus klikken en lezen zou ik zeggen.
Ja ik heb gelezen en gebruik ook Google maar omdat ik nog maar een paar weken met PHP bezig ben begrijp ik echt niet wat ik moet doen. Ik neem aan dat ik de code van session.php ook in autoload.php moet zetten omdat autoload.php op de zelfde manier de tabel moet aanspreken.

Reageren