gboolean secure,
                           gboolean http_only)
 {
-       char *ret;
+       gchar *ret;
+       GString *str;
 
        char *cur = g_strdup (setlocale (LC_TIME, NULL));
 
        setlocale (LC_NUMERIC, "C");
 
-       ret = g_strdup_printf ("Set-Cookie: %s=%s%s",
-                              name,
-                              value,
-                              expires != NULL ? g_date_time_format (expires, "; expires=%a, %d-%b-%Y %H:%M:%S GMT") : "",
-                              domain != NULL ? g_strdup_printf ("; domain=%s", domain) : "",
-                              path != NULL  ? g_strdup_printf ("; path=%s", path) : "",
-                              secure ? g_strdup ("; secure") : "",
-                              http_only ? g_strdup ("; httponly") : "");
+       str = g_string_new ("Set-Cookie: ");
+       g_string_append_printf (str, "%s=%s",
+                                                       name,
+                                                       value);
+       if (expires != NULL)
+               {
+                       g_string_append_printf (str, "%s", g_date_time_format (expires, "; expires=%a, %d-%b-%Y %H:%M:%S GMT"));
+               }
+       if (domain != NULL)
+               {
+                       g_string_append_printf (str, "; domain=%s", domain);
+               }
+       if (path != NULL)
+               {
+                       g_string_append_printf (str, "; path=%s", path);
+               }
+       if (secure)
+               {
+                       g_string_append (str, "; secure");
+               }
+       if (http_only)
+               {
+                       g_string_append (str, "; httponly");
+               }
 
        setlocale (LC_TIME, cur);
        g_free (cur);
 
+       ret = g_strdup (str->str);
+       g_string_free (str, TRUE);
+
        return ret;
 }
 
 
                                                         g_date_time_add_months (g_date_time_new_now_utc (), 3), NULL, NULL, FALSE, FALSE));
        g_string_append_printf (header,
                                "\n%s",
-                               zak_cgi_main_set_cookie ("SECONDO", "il secondo cookie", NULL, NULL, NULL, FALSE, FALSE));
+                               zak_cgi_main_set_cookie ("SECONDO", "il secondo cookie", NULL, NULL, "/", FALSE, TRUE));
+
+       syslog (LOG_MAKEPRI(LOG_SYSLOG, LOG_DEBUG), "header: %s", header->str);
 
        zak_cgi_main_out (header->str, str->str);
        g_string_free (str, TRUE);
 
        return 0;
 }
-