引用cgic中cookie写如下程序:
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=http://bbs.chinaunix.net/test3>111</a>");
会员注册
会员登录
个人空间
发表评论