Skip to content

Instantly share code, notes, and snippets.

@stojg
Last active September 27, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stojg/1280007 to your computer and use it in GitHub Desktop.
Save stojg/1280007 to your computer and use it in GitHub Desktop.
How to set a custom session id on a SilverStripe site
<?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