cgic问题,麻烦看看
bjiang
|
1#
bjiang 发表于 2007-03-19 11:42
cgic问题,麻烦看看
麻烦看看如下程序:
test1: #include <stdio.h> #include "cgic.h" #include <string.h> #include <stdlib.h> #if 1 #define SERVER_NAME cgiServerName #endif void CookieSet(); int cgiMain() { CookieSet(); cgiHeaderContentType("text/html"); printf("<form name=\"form1\" method=\"post\" action=\"test2\">"); printf("<input name=cname type=text size=15 maxlength=8>"); printf("<br>"); printf("<input name=cvalue type=text size=15 maxlength=8>"); printf("<input name=\"Submit\" type=\"submit\" class=\"button\" value=\"提交\">"); printf("</form>"); return 0; } void CookieSet() { char cname[1024]; char cvalue[1024]; /* Must set cookies BEFORE calling cgiHeaderContentType */ cgiFormString("cname", cname, sizeof(cname)); cgiFormString("cvalue", cvalue, sizeof(cvalue)); //printf("strlen(cname)=%d\n",strlen(cname)); if (strlen(cname)) { /* Cookie lives for one day (or until browser chooses to get rid of it, which may be immediately), and applies only to this script on this site. */ cgiHeaderCookieSetString(cname, cvalue, 86400, cgiScriptName, SERVER_NAME); } } test2: #include <stdio.h> #include "cgic.h" #include <string.h> #include <stdlib.h> void Cookies(); int cgiMain() { cgiHeaderContentType("text/html"); Cookies(); printf("<a href=test3>111</a>"); return 0; } void Cookies() { char **array, **arrayStep; char cname[1024], cvalue[1024]; if (cgiCookies(&array) != cgiFormSuccess) { return; } printf("*arrayStep=%d\n",*arrayStep); arrayStep = array; fprintf(cgiOut, "<table border=1>\n"); fprintf(cgiOut, "<tr><th>Cookie<th>Value</tr>\n"); while (*arrayStep) { char value[1024]; fprintf(cgiOut, "<tr>"); fprintf(cgiOut, "<td>"); cgiHtmlEscape(*arrayStep); fprintf(cgiOut, "<td>"); cgiCookieString(*arrayStep, value, sizeof(value)); cgiHtmlEscape(value); fprintf(cgiOut, "\n"); arrayStep++; } fprintf(cgiOut, "</table>\n"); cgiFormString("cname", cname, sizeof(cname)); cgiFormString("cvalue", cvalue, sizeof(cvalue)); if (strlen(cname)) { fprintf(cgiOut, "New Cookie Set On This Call:<p>\n"); fprintf(cgiOut, "Name: "); cgiHtmlEscape(cname); fprintf(cgiOut, "Value: "); cgiHtmlEscape(cvalue); } cgiStringArrayFree(array); } 我不明白为什么printf("*arrayStep=%d\n",*arrayStep);为0 cookie没有保存我的内容?请问用过cgic库的大侠指点下 test3: #include <stdio.h> #include "cgic.h" #include <string.h> #include <stdlib.h> void Cookies(); int cgiMain() { cgiHeaderContentType("text/html"); Cookies(); return 0; } void Cookies() { char **array, **arrayStep; char cname[1024], cvalue[1024]; if (cgiCookies(&array) != cgiFormSuccess) { return; } arrayStep = array; fprintf(cgiOut, "<table border=1>\n"); fprintf(cgiOut, "<tr><th>Cookie<th>Value</tr>\n"); printf("*arrayStep=%d\n",*arrayStep); while (*arrayStep) { char value[1024]; fprintf(cgiOut, "<tr>"); fprintf(cgiOut, "<td>"); cgiHtmlEscape(*arrayStep); fprintf(cgiOut, "<td>"); cgiCookieString(*arrayStep, value, sizeof(value)); printf("value=%s\n",value); cgiHtmlEscape(value); fprintf(cgiOut, "\n"); arrayStep++; } fprintf(cgiOut, "</table>\n"); cgiFormString("cname", cname, sizeof(cname)); cgiFormString("cvalue", cvalue, sizeof(cvalue)); if (strlen(cname)) { fprintf(cgiOut, "New Cookie Set On This Call:<p>\n"); fprintf(cgiOut, "Name: "); cgiHtmlEscape(cname); fprintf(cgiOut, "Value: "); cgiHtmlEscape(cvalue); fprintf(cgiOut, "<p>\n"); fprintf(cgiOut, "If your browser accepts cookies (many do not), this new cookie should appear in the above list the next time the form is submitted.<p>\n"); } //cgiStringArrayFree(array); } |