This chapter discusses how one should manage sessions, that is, share state between multiple HTTP requests from the same user. We use a simple example where the user submits multiple forms and the server is supposed to accumulate state from all of these forms. Naturally, as this is a network protocol, our session mechanism must support having many users with many concurrent sessions at the same time. In order to track users, we use a simple session cookie. A session cookie expires when the user closes the browser. Changing from session cookies to persistent cookies only requires adding an expiration time to the cookie. The server creates a fresh session cookie whenever a request without a cookie is received, or if the supplied session cookie is not known to the server. @heading Looking up the cookie Since MHD parses the HTTP cookie header for us, looking up an existing cookie is straightforward: @verbatim const char *value; value = MHD_lookup_connection_value (connection, MHD_COOKIE_KIND, "KEY"); @end verbatim Here, "KEY" is the name we chose for our session cookie. @heading Setting the cookie header MHD requires the user to provide the full cookie format string in order to set cookies. In order to generate a unique cookie, our example creates a random 64-character text string to be used as the value of the cookie: @verbatim char value[128]; char raw_value[65]; for (unsigned int i=0;i