diff --git a/include/class.ostsession.php b/include/class.ostsession.php
index d27debae7a795859e7b37a0596e19516ee4aa1bc..e588f618525bf715b576dd1b03a174f116638ca6 100644
--- a/include/class.ostsession.php
+++ b/include/class.ostsession.php
@@ -26,8 +26,12 @@ class osTicketSession {
         if(!$this->ttl)
             $this->ttl=SESSION_TTL;
 
+        // Set osTicket specific session name.
         session_name('OSTSESSID');
 
+        // Forced cleanup on shutdown
+        register_shutdown_function('session_write_close');
+
         if (OsticketConfig::getDBVersion())
             return session_start();
 
@@ -56,8 +60,6 @@ class osTicketSession {
             array(&$this, 'destroy'),
             array(&$this, 'gc')
         );
-        //Forced cleanup.
-        register_shutdown_function('session_write_close');
 
         //Start the session.
         session_start();