⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cookie2.c

📁 JAVA分布式程序学习的课件(全英文)
💻 C
字号:
/* cookie2.c - source code for cookie2.cgi
   Author: M. L. Liu.
   This CGI script, invoked by the web page generated by 
   cookie.cgi, receives the state data placed in cookies
   created by cookie.cgi.
*/ 

#include <stdio.h>
#ifndef NO_STDLIB_H
#include <stdlib.h>
#else
char *getenv();
#endif

#define MAX_ENTRIES 10000

typedef struct {
    char name[128];
    char val[128];
} cookieEntry;

char *makeword(char *line, char stop);
char *fmakeword(FILE *f, char stop, int *len);
char x2c(char *what);
void unescape_url(char *url);
void plustospace(char *str);

void getword(char *word, char *line, char stop);

main(int argc, char *argv[]) {
    cookieEntry cEntries[MAX_ENTRIES]; 
     /* storage for the name-value pairs retrieved 
        from HTTP_COOKIE */
    register int x,m=0;
    int cl;
    char* cookieString;

/* Code for query-string omitted for simplicity. */

/* retrieve state data from cookies */
    cookieString = getenv("HTTP_COOKIE");
    if(cookieString == NULL) {
        printf("No cookie information received.\n");
        exit(1);
    }
    printf("Content-type: text/html%c%c",10,10);

    printf("<body bgcolor=\"#CCFFCC\">");
    printf("<H1>Cookie received</H1>");
    printf("The cookie string is: %s\n", cookieString);
    for(x=0;cookieString[0] != '\0';x++) {
        m=x;
        getword(cEntries[x].val,cookieString,';');
        plustospace(cEntries[x].val);
        unescape_url(cEntries[x].val);
        getword(cEntries[x].name,cEntries[x].val,'=');
    }

    printf("<p>The following name/value pairs are received
           from cookies:<p>%c",10);
    printf("<ul>%c",10);
    for(x=0; x <= m; x++)
        printf("<li> <code>%s = %s</code>%c", 
            cEntries[x].name, cEntries[x].val,10);      
    printf("</form>\n<hr></html>");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -