To determine whether a cookie is in the open state

Source: Internet
Author: User
Cookie|cookies always have new portable questions about cookies, here I find a good article, you share.
==================================================
When a developer uses the session variable, the client browser must be required to support receiving cookies, and when the ASP starts a session, it sends a cookie to the client with a label (SessionID). Through this sign, The ASP will then be able to confirm the session and therefore maintain the status. So, before you use the session variable, you need to confirm that the cookie is accepted. Here I explain two methods:


Method One:
Whenever you are between two pages, there is a very simple and reliable way: request a SessionID on the first page, pass it to the next page. Compare the SessionID to the page request. The same description of the client browser accept cookies, the difference is not accepted. It's very simple.
For example, you can put one on the first page (hidden field) and write the SessionID to it. After submitting, remove the SessionID from the page data. Like this:
<form name= "Form1" method= "post" action= "sessions2.asp" >
Username:<input name= "UserName" ><br>
Password:<input name= "UserPassword" >
<input type= "hidden" name= "Thesessionid" value= "<%=Session.SessionID%>" ><br>
<input type= "Submit" value= "Submit" >
</form>
On the second page we will judge whether the SessionID is the same.
<%
Dim Thesessionid
Thesessionid = Request.Form ("Thesessionid")
If Thesessionid = Session.SessionID Then
"When they are equal, the cookie function opens
Response.Write "Cookie is turned on"
Else
"If they are equal, the cookie feature is turned off
Response.Write "Cookie doesn't open!"
End If
%>


Method Two:
You can also use this method to first write a cookie in a page, such as:
<%
Response.Cookies ("status") = "Onoroff"
%>
Read this cookie on the second page:
<%
If Request.Cookies ("status") = "" Then
"When Cookies (" status ") do not have a value, the cookie function is not turned on
Response.Write "Cookie doesn't open!"
Else
"When Cookies (" status ") have a value, the cookie function opens
Response.Write "Cookie is turned on"
End If
%>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.