1
【方法1】
(1) 设置cookie
printf( "Set-Cookie:username=%s; path=/; \r\n ",username);
printf("Content-type: text/html\n\n");
注意:设置cookie的语句要放在Content-type前,否则不能生效。
(2) 查看cookie
printf("Content-type: text/html\n\n");
printf("<html>\n");
info=getenv("HTTP_COOKIE");
if(info!=NULL)
{
sscanf(info,"username=%s",username);
}
注意:HTTP_COOKIE而不是HTTP-COOKIE,很多网络资料上都写错了,结果查到的cookie数据为空。
【参考网址】
http://www.purplepixie.org/cgi/howto.php
【方法2】
(1) 设置cookie
printf("<head>\n");
printf("<script charset=\"gb2312\" language=\"JavaScript\&