Joke Collection Website - News headlines - What should I do if Cookie becomes garbled when it encounters Chinese characters?

What should I do if Cookie becomes garbled when it encounters Chinese characters?

Cookies are often mentioned by everyone now, so what are cookies and what are their functions?

Cookies are a technology that allows the website server to store a small amount of data on the client's hard drive or memory, or to read data from the client's hard drive. Cookies are a very small text file placed on your hard drive by the web server when you browse a website. It can record information such as your user ID, password, web pages you have browsed, and the time you stayed on it. When you come to the website again, the website learns your relevant information by reading the cookies, and can take corresponding actions, such as displaying a slogan welcoming you on the page, or allowing you to log in directly without entering your ID or password. etc.

Essentially, it can be thought of as your ID card. But Cookies cannot execute as code, do not transmit viruses, are proprietary to you, and can only be read by the server that provided them. The saved pieces of information are stored in the form of "name-value" pairs. A "name/value" pair is just a named piece of data. A website can only obtain the information it places on your computer. It cannot obtain information from other Cookies files or anything else on your computer.

Most of the content in Cookies has been encrypted, so the average user appears to be just some meaningless alphanumeric combinations, and only the server's CGI handler knows their true meaning.

Since Cookies are text files or data in memory that are transferred to the user's computer hard drive by the websites we browse, the location where they are stored on the hard drive is closely related to the operating system and browser used. In Windows 9X system computers, the location where Cookies files are stored is C: WindowsCookies. On Windows NT/2000/XP computers, the location where Cookies files are stored is C: Documents and Settings Username Cookies.

The Cookies file in the hard disk can be read by the Web browser, and its command format is: username@website address [number].txt. For example, the name of a Cookies file in the author's computer is: ch@163[1].txt. It should be noted that cookies on the hard disk are text files, not programs.

Cookies Settings

You can select "Settings/View Files" in the "General" tab of "Tools/Internet Options" in IE to view all files saved to your computer. Cookies in. These files are usually named in the format user@domain, where user is your local username and domain is the domain name of the website you are visiting. If you use the NetsCape browser, it is stored in "C: PROGRAMFILESNETS-CAPEUSERS". Different from IE, NETSCAPE uses a cookie file to record the cookies of all websites.

We can set appropriate cookies: open the "Privacy" tab in "Tools/Internet Options" (note that this setting only exists in IE6.0, other versions of IE can click "Tools/ Click the "Custom Level" button in the "Security" tab of Internet Options to make simple adjustments) to adjust the security level of cookies. Normally, it can be adjusted to the "medium-high" or "high" position. Most forum sites require the use of cookie information. If you never go to these places, you can adjust the security level to "Block All Cookies"; if you just want to ban cookies from individual websites, you can click the "Edit" button to block the websites. Add to list.

In the "Advanced" button option, you can set first-party cookies and third-party cookies. First-party cookies are cookies from the website you are browsing, and third-party cookies are cookies sent to you by a website other than those you are browsing. Usually you have to choose "reject" for third-party cookies. If you need to save cookies, you can use IE's "Import and Export" function, open "File/Import and Export", and follow the prompts.

2:

Writing and reading of Cookies

The Cookies collection is a data collection attached to the Response object and the Request object. It needs to be added in front when using it. on Response or Request.

The syntax used to send Cookies to the client is usually:

When setting a set of Cookies that does not exist, it will be created on the client. If the Cookies already exist, then will be replaced. Since Cookies are sent to the client as part of the header information of HTTP transmission, the code for sending Cookies to the client is generally placed before the tag of the HTML file sent to the browser.

If the user wants to read Cookies, he must use the Cookies collection of the Request object. The usage method is:

It should be noted that only when the server has not downloaded any data for browsing The browser can exchange data on the Cookies set with the Server in front of the server. Once the browser starts to receive the data downloaded by the Server, the data exchange of Cookies will stop. In order to avoid errors, response.Buffer=True must be added in front of the program and the server.

3:

Application of Cookies

Almost all website designers use cookies when designing websites, because they all want to provide users who browse the website It provides users with a more friendly and humanistic browsing environment, and can also collect visitor information more accurately.

Website visitor number management

Due to the use of proxy servers, caches, etc., the only way to help a website accurately count the number of visitors is to create a unique ID for each visitor. Using cookies, the website can complete the following tasks: determine how many people have visited; determine how many of the visitors are new users (that is, the first visit) and how many are old users; determine how often a user visits the website.

Usually, website designers use back-end databases to achieve the above purposes. When a user visits the website for the first time, the website creates a new ID in the database and sends the ID to the user through a cookie. When the user visits again, the website adds 1 to the counter corresponding to the user ID to obtain the user's number of visits or determine whether the user is a new user or an old user.

Customize the appearance of web pages according to user preferences

Some website designers provide users with the power to change the content, layout and color of web pages, allowing users to enter their own information, and then pass This information modifies some parameters of the website to customize the appearance of the web page.

Implement functions such as "shopping basket" in e-commerce sites

You can use cookies to record the user's ID, so that when you put new things into the "shopping basket", The website can record it and record it corresponding to your ID in the website's database. When you "pay", the website can know what is in your "shopping basket" by retrieving all your choices in the database by ID.

In general cases, the website's database can save the content you choose, the web pages you browse, the information you fill in the form, etc.; and the cookie containing your unique ID is saved on your computer.

4:

Defects of Cookies

Although cookies are widely used, they can perform some functions that are impossible to achieve using other technologies.

However, there are also some imperfect aspects that bring inconvenience to the application.

The problem of multiple people using one computer

Any computer in a public place or many computers used in the office or at home will be used by two or more people at the same time. people use. In this way, when you use it to shop in an online supermarket, the online supermarket or website will leave a cookie on this machine. Someone may try to use your account to shop in the future, which brings the possibility of insecurity. Of course, on some computers using multi-user operating systems such as Windows NT or UNIX, this will not be a problem. Because in multi-user operating systems, the cookies of different accounts are placed in different places.

When Cookies are Deleted

If your browser does not work properly, you may delete all temporary Internet files on your computer. However, once you do this, you will lose all cookies. When you visit a website again, the website will consider you a new user and assign you a new user ID and a new cookie. The result will be a deviation in the ratio of new and old users in website statistics, and it will be difficult for you to restore the parameter selections saved in the past.

When one person uses multiple computers

Some people often use more than one computer in a day. For example, there is a computer in the office, another at home, and a laptop for mobile work. Unless the website uses special technology to solve this problem, you will have three different cookie files on the three machines, and any website visited on the three machines will see you as three different users.

5:

Prevent Cookies from being leaked

Want to know whether the website you visited has written Cookie information on your hard drive or memory? Just follow the steps below to understand and control the cookie information of the website you are visiting.

Step 1: Click "Tools" "In-ernet Options" in the IE window to open the "Internet Options" settings window;

Step 2: Click "In-ernet Options" in the "Internet Options" settings window "Security" tab, and then click the "Custom Level" button to enter the "Security Settings" window;

Step 3. Find the "Cookies" setting item in the "Security Settings" window. There are two sub-options under the "Cookies" setting item, among which "Allow the use of cookies stored on your computer" is for Cookie files stored on the user's computer hard drive; "Allow the use of per-session cookies (not stored)" is for Cookie information stored in the user's computer memory. Cookie files stored on your hard drive are permanent, while Cookie information stored in memory is temporary. If you want IE to prompt you when it is about to receive all cookies from a Web site, you can select the "Prompt" item in the two sub-options above. Of course, you can also select "Enable" to allow IE to accept all Cookie information (this is also IE's default option); select "Disable" to not allow Web sites to store Cookies on your computer, and Web sites will also Cookies already on your computer cannot be read.

IE6.0 provides more reliable personal privacy and security protection measures, allowing users to control how much information the browser sends out. A new "Privacy" tab (Figure 1) has been added to the "Internet Options" window, where users can directly set the privacy level when browsing and control the cookies used by other sites on their computers as needed.

If the site we are browsing uses cookies, there will be a yellow exclamation mark in the browser status bar. Double-click it to open the "Privacy Report" dialog box, where the user can view the specific privacy policy, or directly click Adjust the security privacy level in the above-mentioned "Privacy" tab after pressing the "Settings" button.

The "Delete Cookies" button (Figure 2) has also been added to the "General" tab to facilitate users to directly clear Cookies on the machine. In addition, some options to further improve security (such as clearing temporary Internet files when closing the browser) have been added to the "Tools" "Options" "Advanced" tab. In fact, how to better protect personal privacy and security is a key technology in Microsoft's next-generation ".NET" strategic software, and now IE6.0 has tried to take the first step.

In addition, because not all Cookie information is stored in the computer in the form of files, some information is also stored in the memory. For example, when you browse a website, the web server will automatically generate cookies in the memory, and automatically delete the cookies when you close the IE browser. In that case, the two methods introduced above will not work. We need to use registry editing. to modify system settings. It should be noted that before modifying the registry, please make a backup so that it can be restored smoothly if problems occur.

Run Regedit and find the following key value: HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersionInternet SettingsCacheSpecial PathsCookies. This is the key value of Cookies in memory. Delete this key value. At this point, no matter what form Cookies exist in, we no longer have to be afraid.

The last point that needs to be explained is: although eliminating cookies can enhance the information security of your computer, doing so will also have some disadvantages. For example, on some web pages that require cookie support, some inexplicable errors will occur. A typical example is that you will no longer be able to use the free mailbox of some websites in the future.

6:

Cookies Spoofing

By analyzing the format of Cookie, we know that the last two items are its URL path and domain name respectively. The identification relies on these two parameters. Under normal circumstances, the URL we enter when browsing a website is its domain name, which needs to be converted into an IP address through the domain name management system DNS before connecting. If we can make some settings on the DNS and map the IP address of the target domain name to other sites, we can illegally access the cookies of the target site.

It is actually very simple to spoof cookies. For example, in the installation directory under Win9X, there is a file named hosts.sam. After opening it in text mode, you will see this format:

127.0.0.1 localhost

After setting , you can realize the localization of domain name resolution. Just add the IP and domain name to the file according to the above format and save it as hosts. The hosts file can actually be regarded as a local DNS system. It can be responsible for interpreting domain names into IP addresses. Its priority is higher than the DNS server. Its specific implementation is part of the TCP/IP protocol.

For example, if we want to read the Cookies information generated by the target site www.abc.com, we can use www.def.com (our own site). Store the files needed for deception in www.def.com, and use it to read and modify the other party's cookies.

Step 1: Ping the IP address of www.def.com:

Ping www.def.com

Reply from 192.168.0.1: bytes=32 time =20ms TTL=244

Then modify the hosts.sam file as follows:

192.168.0.1 www.abc.com

And save it as hosts file.

Step 2: Read Cookies information:

Transmit the page used to read Cookies to www.def.com. At this time, connect to www.abc.com. Since we are Modification of the local DNS domain name resolution. At this time, the network connection is not www.abc.com, but www.def.com.

In this way, the local cookie set by www.abc.com can be read.

Step 3 In the same way, you can modify the read data and write the modified information into Cookie. After the modification is completed, delete the hosts file and re-enter www.abc.com. The Cookies data used at this time is the data you specified.

In short, although Cookies can be deceived to a certain extent and bring insecurity to network applications, the Cookies file itself will not cause the leakage of user privacy, nor will it provide hackers with Trojan horse program carriers, as long as they are used reasonably, will bring convenience to website administrators in maintaining and managing the website and to users.

7:

The Cookies collection has the following attributes

1. Expires attribute: This attribute is used to set a period for Cookies. During the period, as long as it is opened The web page can call the saved cookies. If this period expires, the cookies will be automatically deleted. For example:

Set the validity period of Cookies to April 1, 2004, and they will be automatically deleted at that time. If a cookie does not have a validity period set, its life cycle starts from opening the browser and ends when the browser is closed. The life cycle will end after each run and will start again the next time it runs.

2.Domain attribute: This attribute defines the uniqueness of the data transmitted by Cookies. If you only send certain cookies to the Sohu homepage, you can use the following code:

3.Path attribute: It defines that cookies are only sent to the specified path request. If the Path attribute is not set, use the application The default path of the software.

4.Srcure attribute: Specifies whether Cookies can be read by users.

5.Haskeys attribute: If the requested Cookies is a Cookies dictionary with multiple key values, True is returned, which is a read-only attribute.