diff --git a/lib/util.php b/lib/util.php
index 7e8fc9b6bb7c728fab9082b423661ba73bb3f4e9..1fa3ad765d0c0e5c4d2683687472862e8630b9d9 100755
--- a/lib/util.php
+++ b/lib/util.php
@@ -411,18 +411,19 @@ class OC_Util {
 		exit();
 	}
 
-	/**
-	 * get an id unqiue for this instance
-	 * @return string
-	 */
-	public static function getInstanceId() {
-		$id=OC_Config::getValue('instanceid', null);
-		if(is_null($id)) {
-			$id=uniqid();
-			OC_Config::setValue('instanceid', $id);
-		}
-		return $id;
-	}
+    /**
+     * get an id unique for this instance
+     * @return string
+     */
+    public static function getInstanceId() {
+        $id = OC_Config::getValue('instanceid', null);
+        if(is_null($id)) {
+            // We need to guarantee at least one letter in instanceid so it can be used as the session_name
+            $id = 'oc' . uniqid();
+            OC_Config::setValue('instanceid', $id);
+        }
+        return $id;
+    }
 
 	/**
 	 * @brief Static lifespan (in seconds) when a request token expires.
diff --git a/tests/lib/util.php b/tests/lib/util.php
index 1c9054264c9c7e1ac34d212f3aea7e8d8683f6f0..1f253825920cb6860b4ab5c0c549640268dce3b6 100644
--- a/tests/lib/util.php
+++ b/tests/lib/util.php
@@ -54,4 +54,9 @@ class Test_Util extends PHPUnit_Framework_TestCase {
 		$this->assertEquals('no-reply@example.com', $email);
 		OC_Config::deleteKey('mail_domain');
 	}
+
+  function testGetInstanceIdGeneratesValidId() {
+    OC_Config::deleteKey('instanceid');
+    $this->assertStringStartsWith('oc', OC_Util::getInstanceId());
+  }
 }