Example from jklee, 2001/8/31
Go-Forms
Using in process CGI:
/* in-process CGI append this code to main.c */ static void sampleCookieFor(webs_t wp, char_t* path, char_t* query) { websWrite(wp, T("HTTP/1.0 200 OK\n")); websWrite(wp, T("Server: GoAhead-Webs\r\n")); websWrite(wp, T("Pragma: no-cache\n")); websWrite(wp, T("Cache-control: no-cache\n")); websWrite(wp, T("Content-Type: text/html\n")); websWrite(wp, T("Set-Cookie: name=jklee; path=/; expires=Wednesday, 29-Nov-02 23:12:40 GMT\n")); websWrite(wp, T("Set-Cookie: where=office; path=/; expires=Wednesday, 29-Nov-02 23:12:40 GMT\n")); websWrite(wp, T("\n")); websWrite(wp, T("<html><head></head><body bgcolor=#FFFFFF><pre>\n")); websWrite(wp, T("Cookie: {%s}\n\n"), wp->cookie); websWrite(wp, T("</pre></body></html>\n")); websDone(wp, 200); }
Traditional CGI
Using a C program for CGI. The code has to be compiled and the binary placed in the cgi-bin directory.
#include <stdio.h> #include <string.h> #include <stdlib.h> int main(int argc, char *argv[]) { printf("HTTP/1.0 200 OK\n"); printf("Server: GoAhead-Webs\r\n"); printf("Pragma: no-cache\n"); printf("Cache-control: no-cache\n"); printf("Content-Type: text/html\n"); printf("Set-Cookie: name=jklee; path=/; expires=Wednesday, 29-Nov-02 23:12:40 GMT\n"); printf("Set-Cookie: where=office; path=/; expires=Wednesday, 29-Nov-02 23:12:40 GMT\n"); printf("\n"); printf("<html><head></head><body bgcolor=#FFFFFF><pre>\n"); printf("SERVER_SOFTWARE: %s\n\n",getenv("SERVER_SOFTWARE")); printf("Cookie: %s\n\n",getenv("HTTP_COOKIE")); printf("</pre></body></html>\n"); return 0; }