< %@ LANGUAGE="VBSCRIPT" % > < % RequestName = Request.Form("Name") RequestLeaveMeAlone = Request.Form("LeaveMeAlone") If RequestName < >"" or RequestLeaveMeAlone < >"" then Response.Cookies("MySiteVisitorName") = RequestName Response.Cookies("MySiteVisitorName").Expires = #January 01, 2010# Response.Cookies("MySiteLeaveMeAlone") = RequestLeaveMeAlone Response.Cookies("MySiteLeaveMeAlone").Expires = #January 01, 2010# End if VisitorName = request.cookies("MySiteVisitorName") LeaveMeAlone = request.cookies("MySiteLeaveMeAlone")
If VisitorName ="" and LeaveMeAlone ="" then % > < HTML > < HEAD > < /HEAD > < body bgcolor="#ccffff" text="black" link="navy" vlink="purple" > < DIV ALIGN="CENTER" > < form action="index.asp" method="POST" > < H2 >Let's be friends< /H2 > What's your name (leave blank and hit the Submit button if you don't want us to know)? < input type="text" name="name" >< BR >< BR > < input type="hidden" name="LeaveMeAlone" value="x" > < input type="submit" value="Submit" > < /FORM > < /DIV > < /BODY > < % End if If VisitorName < > "" then Response.write "Hi, " & VisitorName & "! I hope you are having a great day!" End if 'rest of the page % > 好,現在來看看上面的代碼實現執行了什么。首先,設置頁面。然后,檢查表單變量(在同一個頁面中)。如果表單變量存 在,就創建cookie,并設置到期時間。
< %@ LANGUAGE="VBSCRIPT" % > < % RequestName = Request.Form("Name") RequestLeaveMeAlone = Request.Form("LeaveMeAlone") If RequestName < >"" or RequestLeaveMeAlone < >"" then Response.Cookies("MySiteVisitorName") = RequestName Response.Cookies("MySiteVisitorName").Expires = #January 01, 2010# Response.Cookies("MySiteLeaveMeAlone") = RequestLeaveMeAlone Response.Cookies("MySiteLeaveMeAlone").Expires = #January 01, 2010# End if
If VisitorName ="" and LeaveMeAlone ="" then % > < HTML > < HEAD > < /HEAD > < body bgcolor="#ccffff" text="black" link="navy" vlink="purple" > < DIV ALIGN="CENTER" > < form action="index.asp" method="POST" > < H2 >Let's be friends< /H2 > What's your name (leave blank and hit the Submit button if you don't want us to know)? < input type="text" name="name" >< br >< br > < input type="hidden" name="LeaveMeAlone" value="x" > < input type="submit" value="Submit" > < /FORM > < /DIV > < /BODY > < % End if 如果cookie已經存在,并且用戶名字存在,就顯示給訪問者一個歡迎界面,然后執行其余的代碼。
If VisitorName < > "" then Response.write "Hi, " & VisitorName & "! I hope you are having a great day!" End if 'rest of the page % > 盡管上面的這個例子很簡單,但可以從中擴展許多富有創造力的應用。你可以在表單中加入許多功能,以便定制化web站點。 你還可以讓訪問者定制網站的色彩、字體,以至于其他web元素。有可能的話,你可以詢問訪問者的生日,當訪問者在那一天來訪 時,你就可以顯示“生日快樂”的信息給他。