?? cookies.c
字號:
#include <stdio.h>#include <stdlib.h> /* for getenv */#include <string.h>/* extract a list of cookies from the HTTP_COOKIE environment variable. fills in 2 arrays with the names and values of each cookie found. cookies are seperated by the ';'. returns the number of cookies found. the cookie names are put in the array names, the values in vals - this function assumes both exist and have room for maxcookies elements (each element is a (char *). I have a hard time with a variable named maxcookies, since there is no such thing as a maximum number of cookies. There are never enough cookies for me...*/int get_cookies(char **names, char **vals, int maxcookies) { int n=0; char *cookies; char *ptr; char *eqs; cookies = getenv("HTTP_COOKIE"); if (! cookies) return(0); /* no cookies found (sigh...) */ ptr = strtok(cookies,";"); while (ptr) { /* while cookies remain */ /* find the = sign everything before it is the name and everything after it is the value */ eqs = strchr(ptr,'='); if (!eqs) break; /* not found - give up */ *eqs=0; if (*ptr==' ') ptr++; names[n]=strdup(ptr); /* make a copy of the cookie name */ vals[n] = strdup(eqs+1); /* make a copy of the cookie value */ /* if everything worked - move on otherwise give up looking any furthur */ if (names[n] && vals[n]) { n++; } else { break; /* some problem, give up and return what we now have */ } ptr = strtok(NULL,";"); } return(n);}/* given a pair of arrays containing pointers to cookie names and values, extract a named cookie and return it's value */char *cookie_lookup(char **names, char **vals, int num, char *cookiename) { int i; int len = strlen(cookiename); for (i=0;i<num;i++) { if (strncmp(names[i],cookiename,len)==0 ) { /* found it - return the value */ return(vals[i]); } } return(NULL);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -