Liebe Listenfreunde,
ich baue an einer extbase-extension, die Sachen in der Session speichert, und zwar für angemeldete und un-angemeldete User. die daten in der Session sind etwa vergleichbar mit einem Warenkorb, in meinem Fall ist es ein Spielstand.
Soweit funktioniert es auch erstmal.
Meldet sich ein User an, sichere ich die serialisierte Session in einem Feld im fe_user, bzw. hole die session dann aus dem fe_user wieder hervor. auch das funktioniert.
Allerdings hält die Spielstand-Session scheints viel länger als die fe_user-Session, so daß wir jetzt manchmal die Situation haben, daß der fe_user automatisch abgemeldet wurde, der Spielstand aber weiterexistiert.
Wie kann ich die Haltbarkeit der Session-Variable beeinflussen? Als Workaround könnte ich natürlich im Spielstand kennzeichnen ob er mit login ist, und das überprüfen, aber ich will die Spielstände auch ohne login nicht bis ans Ende der Tage behalten.
hat das jemand schonmal gehabt und könnte helfen?
viele Grüße von der Sabine
Classes/Domain/Session/SessionHandler.php
<?php
namespace TYPO3\MyGame\Domain\Session;
/***************************************************************
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* session handling
*
* @package my_game
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*
*/
class SessionHandler implements \TYPO3\CMS\Core\SingletonInterface {
/**
* Returns the object stored in the user´s PHP session
* @return Spielstand the stored spielstand
*/
public function restoreFromSession() {
$sessionData = $GLOBALS['TSFE']->fe_user->getKey('ses', 'tx_mygame_spielstand');
return unserialize($sessionData);
}
/**
* Writes an object into the PHP session
* @param $object any serializable object to store into the session
* @return \TYPO3\MyGame\Domain\Session\SessionHandler this
*/
public function writeToSession($spielstand) {
$sessionData = serialize($spielstand);
$GLOBALS['TSFE']->fe_user->setKey('ses', 'tx_mygame_spielstand', $sessionData);
$GLOBALS['TSFE']->fe_user->storeSessionData();
return $this;
}
/**
* Cleans up the session: removes the stored object from the PHP session
* @return \TYPO3\MyGame\Domain\Session\SessionHandler this
*/
public function cleanUpSession() {
$GLOBALS['TSFE']->fe_user->setKey('ses', 'tx_mygame_spielstand', NULL);
$GLOBALS['TSFE']->fe_user->storeSessionData();
return $this;
}
}
?>