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

📄 showcookies.c

📁 this gives details of the network programming
💻 C
字号:
/* CGI program that simply sets a cookie */#include <stdio.h>#include <stdlib.h>	/* for getenv */#include <time.h>#include <string.h>#include "cgilib.h"#include "cookies.h"char *http_header = "content-type: text/html\r\n\r\n";#define MAXFIELDS 20int main( ) {    char *query;  char *names[MAXFIELDS];	/* form field names */  char *vals[MAXFIELDS];	/* form field values */  char *form;  char *cnames[MAXFIELDS];	/* cookie names */  char *cvals[MAXFIELDS];	/* cookie values */  char *cookie;  char *cookiename, *cookieval;  int i,n,n_cookies;  /* always tell the browser what kind of document we are sending */  /* NOTE: the web server that started the CGI program will send     back the appropriate HTTP header !!! */  printf("Content-type: text/html\r\n");  /* Can't send any content yet, since we might want to send a     cookie header (to set a cookie on the client).   */  /* get the query */  query = get_request();  /* get all the cookies that came with the request */  n_cookies=get_cookies(cnames, cvals, MAXFIELDS);  /* parse the request string and chop into fields */  n = split_and_parse(query,names,vals,MAXFIELDS);  cookiename = cookieval = NULL;  /* See if we are supposed to set a cookie */  for (i=0;i<n;i++) {    if (strcasecmp(names[i],"cookiename")==0) {      cookiename = vals[i];    } else if (strcasecmp(names[i],"cookieval")==0) {      cookieval = vals[i];    }  }    if ( (cookiename != NULL) && (cookieval != NULL)) {    /* set a cookie */    printf("Set-cookie: %s=%s;\r\n",cookiename,cookieval);  }  /* End the headers */  printf("\r\n");    if ( (cookiename != NULL) && (cookieval != NULL)) {    printf("I'm setting the cookie: %s=%s<BR>\n",cookiename,cookieval);  }    /* now print out all the cookies we got */    printf("<TITLE>Cookies List</TITLE>\n");  printf("<BODY BGCOLOR=WHITE>\n");  printf("<H3>Here are your cookies</H3>");  printf("<TABLE BORDER=1>\n");  printf("<TR><TH>Name</TH><TH>Value</TH></TR>\n");  for (i=0;i<n_cookies;i++) {    printf("<TR><TD>%s</TD><TD>%s</TD></TR>\n",	   cnames[i],cvals[i]);  }  printf("</TABLE>\n");  printf("<P>\n");printf("<FORM METHOD=GET>Name: <INPUT TYPE=TEXT NAME=cookiename><BR>Value: <INPUT TYPE=TEXT NAME=cookieval><BR><INPUT TYPE=SUBMIT VALUE=\"Press to create new cookie\"></FORM>\n\n");  return(0);}   		  

⌨️ 快捷键说明

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