How to create a cookie with FastCGI (nginx) in C ++

I am building a C ++ site using FastCGI on nginx. My problem is to track the user (aka session). I can read HTTP_COOKIE, but I don’t know how I can create a new cookie with name and value and send it to the client.

On Google, I found only suitable materials for PHP, Python, and other scripting languages ​​that try to work with CGI / fCGI.

+5
source share
1 answer

you can use setcookie syntax.

 #include <stdio.h>
 #include <stdlib.h>

    int main(int argc, char** argv)
    {
        int count = 0;
        printf("Content-type: text/html\r\n"
               "Set-Cookie: name=value\r\n"
               "\r\n"
               "<title>CGI Hello!</title>"
               "<h1>CGI Hello!</h1>"
               "Request number %d running on host <i>%s</i>\n",
               ++count, getenv("SERVER_NAME"));
       return 0;
    }
+6
source

All Articles