如何在C++中使用FastCGI(nginx)创建cookie

al3*_*xst 5 c++ cookies session fastcgi nginx

我正在使用nginx上的FastCGI在C++中创建一个网站.我现在的问题是跟踪用户(也称为会话).我可以读出HTTP_COOKIE,但我不知道如何创建一个带有名称和值的新cookie并将其发送给客户端.

在Google中查找我只发现了PHP,Python和其他尝试使用CGI/fCGI运行的脚本语言的相关内容.

Viv*_*oel 6

你可以使用setcookie语法.

 #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;
    }
Run Code Online (Sandbox Code Playgroud)