Last active
September 27, 2015 13:57
-
-
Save stojg/1280007 to your computer and use it in GitHub Desktop.
How to set a custom session id on a SilverStripe site
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_destroy(); | |
// Start a new session with the token from the url, this will reinitialize the _SESSION | |
Session::start('wished-session-id'); | |
// Set the current session connected to the controller with an new instance with the proper _SESSION data | |
$session = new Session(isset($_SESSION) ? $_SESSION : null); | |
Controller::curr()->setSession($session); | |
// Some test that this actually works | |
$pageviews = 1; | |
if(Session::get('pageviews')){ | |
$pageviews += Session::get('pageviews'); | |
} | |
Session::set('pageviews', $pageviews); | |
// We have to manually save the session, since Director doing it on the wrong instance | |
Session::save(); | |
return Session::get('pageviews'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment