Cross-domain Cookie

Source: Internet
Author: User
All website developers will like the powerful features and ease-of-use of cookies. It plays a powerful role in tracking user information and building a user-friendly and personalized website, this avoids the expensive costs of using databases. However, cookies cannot be transmitted across domains and can only be accessed by those domains that have created them. Here we will discuss how to use ASP to break through this restriction.
Cookie introduction
First, we will give a brief introduction to the Cookie to illustrate how to use ASP to maintain the cookie.
Cookie is a small file stored in the client computer, which means that every time a user visits your site, you can secretly put a file containing the relevant information on its hard disk. This file contains almost any information you want to set, including user information and site status. In this case, there is a potential danger: The information may be read by hackers. To prevent this problem, a valid method is that the cookie can only be accessed by the domain where it is created. For example, can only access cookies created by Generally speaking, there is no problem. But what if two different sites in two different domains need to share the user information stored in cookies? Of course, you can choose to copy user mail. However, what if you want users to register only on one site and become registered users on another site in the East? Or, do two sites share a user database and require automatic user login? At this time, sharing cookies across domains is the best solution.
Here, let's take a look at some ASP cookie processing code for reference later.
'Create Cookie
Response. Cookies ("MyCookie"). Expires = Date + 365
Response. Cookies ("MyCookle"). Domain = ""
Response. Cookies ("MyCookle") ("Username") = strUsername
Response. Cookies ("MyCookle") ("Password") = strPassword
The preceding code creates a cookie and sets attributes for the cookie: Domain, Expiration Time, and other values stored in the cookie. Here, strUsename and strPassword are the variables set in the previous place. Then, read in the cookie using the following statement.
'Read Cookie
DatExpDate = Request. Cookies ("MyCookie ")
StrDomaln = Request. Cookies ("MyCookle"). Domain
StrUsername = Request. Cookies ("MyCookle") ("Username ")
StrPassword = Request. Cookies ("MyCookie") ("Password ")
For more information, see ASP.
The key to sharing cookies is redirection. The general process is as follows:

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: 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.