1 [method 1] (1) Set cookieprintf (Set-Cookie: username % s; path; \ r \ n, username); printf (Content-type: texthtml \ n); note: the cookie setting statement must be placed before Content-type; otherwise, the cookie setting will not take effect. (2) view cookieprintf (Content-type: texthtml \ n); pri
1
Method 1]
(1) set cookie
- Printf (\"Set-Cookie: username= % S;Path= //; Rn \ ", username );
- Printf (\ "Content-type: tExT/htmLnN \");
Note: The cookie setting statement must be placed before Content-type; otherwise, it cannot take effect.
(2) view cookies
- Printf (\ "Content-type: text/htmlnn \");
- Printf (\"<Html>N \");
- Info=Getenv(\ "HTTP_COOKIE \");
- If (info! = NULL)
- {
- Sscanf (info ,\"Username= % S \ ", username );
- }
Note: HTTP_COOKIE instead of the HTTP-COOKIE, many network information is wrong, the result found cookie data is empty.
Method 2]
(1) set cookie
- Printf (\"<Head>N \");
- Printf (\"<ScriptCharSet= \ "Gb2312 \"Language= \ "JavaScript \">N \");
- Printf (\ "fuNcTion setCookie (c_name, value, expirEdAys)
- N {
- NvarExDate=NewDate ();
- Nexdate. setDate (exdate. getDate () + expiredays)
- Ndocument. cookie=C_name+ \ "= \" + Escape (value) +
- N ((Expiredays= Null )? \"\":\";Expires= \ "+ Exdate. toGMTSTrIng ());
- } N \");
- Printf (\" Script>N \");
- Printf (\" Head>N \");
InLabel call:
- Printf (\"<Script Type= \ "Text/javascript \">N \");
- Printf (\ "setCookie (\ 'username \ ', \' % s \ ', 1); n \", username );
- // Printf (\"Window. loCatIon. href= \ "Xxxx \"; n \");
- Printf (\" Script>N \");
(2) obtain the cookie
- Printf (\"<Head>N \");
- Printf (\"<ScriptCharset= \ "Gb2312 \"Language= \ "JavaScript \">N \");
- Printf (\ "function getCookie (c_name)
- N {
- N if (document. cookie. length>0)
- N {
- NC_start=Document. Cookie. indexOf (c_name + \ "= \");
- N if (c_start! =-1)
- N {
- NC_startC_start= C_start + c_name.length + 1;
- NC_end=Document. Cookie. indexOf (\ "; \", c_start );
- N if (C_end=-1)C_end=Document. Cookie. length;
- N return unescape (document. cookie.SuBstring (c_start, c_end ));
- N}
- N}
- N return \"\";
- N} n \");