gpt4 book ai didi

c - 如何使用FastCGI、nginx和C访问cookies?

转载 作者:太空宇宙 更新时间:2023-11-04 03:47:09 26 4
gpt4 key购买 nike

如何访问浏览器发送的 cookie?

设置 cookie 的代码:

#include "fcgi_stdio.h"
#include <stdlib.h>

int main(void)
{
while(FCGI_Accept() >= 0){
printf("Content-type: text/html\r\nSet-Cookie: name=value\r\n\r\n");
printf("REQUEST_METHOD = %s\n<br>", getenv("REQUEST_METHOD"));
printf("QUERY_STRING = %s\n<br>", getenv("QUERY_STRING"));
printf("CONTENT_TYPE = %s\n<br>", getenv("CONTENT_TYPE"));
printf("CONTENT_LENGTH = %s\n<br>", getenv("CONTENT_LENGTH"));
printf("SCRIPT_FILENAME = %s\n<br>", getenv("SCRIPT_FILENAME"));
printf("SCRIPT_NAME = %s\n<br>", getenv("SCRIPT_NAME"));
printf("REQUEST_URI = %s\n<br>", getenv("REQUEST_URI"));
printf("DOCUMENT_URI = %s\n<br>", getenv("DOCUMENT_URI"));
printf("DOCUMENT_ROOT = %s\n<br>", getenv("DOCUMENT_ROOT"));
printf("SERVER_PROTOCOL = %s\n<br>", getenv("SERVER_PROTOCOL"));
printf("REMOTE_ADDR = %s\n<br>", getenv("REMOTE_ADDR"));
printf("REMOTE_PORT = %s\n<br>", getenv("REMOTE_PORT"));
printf("SERVER_ADDR = %s\n<br>", getenv("SERVER_ADDR"));
printf("SERVER_PORT = %s\n<br>", getenv("SERVER_PORT"));
}
}

服务器配置:

events {
worker_connections 1024;
}

http {
server {
listen 80;
server_name localhost;

location /login {
fastcgi_pass 127.0.0.1:9000;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_pass_header Cookie;
}

location ~ \.(gif|jpg|png)$ {
root /data/images;
}
}
}

最佳答案

我找到了答案,只需要读取环境变量HTTP_COOKIE

printf("HTTP_COOKIE = %s\n<br>", getenv("HTTP_COOKIE"));

关于c - 如何使用FastCGI、nginx和C访问cookies?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23362410/

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