protected function writeCookie(array $preferences)
    {
        $data     = implode(',', $preferences);
        $lifetime = time() + self::$preferenceLifetime;
        $path     = '/';
        $server   = explode('.', $_SERVER['SERVER_NAME']);
        $domain   = '';

        for ($i = 2; $i > 0; --$i) {
            $domain = '.'.$server[$i].$domain;
        }

        // Store preferences in cookie and return result
        return setcookie(self::$identifier, $data, $lifetime, $path, $domain);
    }