Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm creating a website in C++ using FastCGI on nginx. My problem is now to track a user (aka session). I can read the HTTP_COOKIE out, but I have no clue how I can create a new cookie with a name and a value and send this to the client.

Looking up in Google I only found relevant stuff for PHP, Python and other scriptlanguages that try to run with CGI/fCGI.

like image 532
al3xst Avatar asked Mar 30 '13 19:03

al3xst


People also ask

What is FastCGI in nginx?

FastCGI is a protocol based on the earlier CGI, or common gateway interface, protocol meant to improve performance by not running each request as a separate process. It is used to efficiently interface with a server that processes requests for dynamic content.

What is FastCGI server?

FastCGI is a programming interface that can speed up Web applications that use the most popular way to have the Web server call an application, the common gateway interface (CGI).


1 Answers

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;
    }
like image 131
Vivek Goel Avatar answered Nov 01 '22 09:11

Vivek Goel