gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:25:24 24 4
gpt4 key购买 nike

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

在 Google 中查找,我只找到了与 PHP、Python 和其他试图与 CGI/fCGI 一起运行的脚本语言相关的内容。

最佳答案

您可以使用 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;
}

关于c++ - 如何在 C++ 中使用 FastCGI (nginx) 创建 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15722795/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com