If you have a bad memory like the author, you may not be able to remember people’s names at all. When I meet people, I mostly just nod, ask "Did you eat?", and expect the greeting to end there
. If I needed to express something, then I would have to resort to some cunning techniques to help me figure out who the other person was. For example, talking nonsense about someone related to the other person, no matter how far apart they are, as long as it can avoid the embarrassment of not remembering the other person's name: "How about your next door neighbor's nephew's cute puppy Mephistopheles? "Through this method, I hope to make the other person feel that I really
value him (her) and even remember these trivial things, although in fact I have forgotten even the name. However, it’s not that I don’t pay attention, it’s that my memory is really bad, and there are too many names
to remember. If I could set cookies for everyone, I wouldn't have this memory problem again.
In this article, we are going to learn:
1. What are Cookies?
2. The composition of Cookies
3. Manipulating Cookies
4. Cookie Monster
What are Cookies?
You may ask, what are cookies? A cookie is a small amount of data saved by the browser on the user's computer. It is associated with a specific WEB page or WEB site and is automatically passed between the WEB browser and
WEB server.
For example, if you are running a Windows operating system and use Internet Explorer to surf the Internet, then you will find a subdirectory under your "Windows" directory called
"Temporary Internet Files". If you take a look at this directory at some point, you'll notice that there are files in there with names that look just like email addresses. For example, in the directory
on my machine, there is a file like "jim@support.microsoft.com". This is a cookie file. Where does this file come from? Guess it, it comes from Microsoft’s support site
dot. By the way, this is not my email address, just to clarify.
Cookies are a great solution for managing small, unimportant details that you don’t want to store in a central database. (That’s not to say that everyone’s names don’t matter.) For example, there are currently a growing number of customization services on the site that can customize the content that each user wants to see. If you were designing a site like this, how would you manage the information that one user
likes a green menu bar, while another prefers a red one. A tiring question indeed. However, such information can be safely recorded in cookies and saved on the user's computer, and your own database space can be reserved for longer-term and more meaningful data.
FYI: Cookies are often useful for security purposes. I don’t want to get too deep into this issue here, but just provide an example of how you can use
cookies that expire after a certain period of time to keep your site secure:
1. Using a username and password, pass SSL login.
2. Check the username and password in the server's database. If the login is successful, create a message digest of the current time stamp (such as MD5) and save it in the cookie and server database. Save the user's login time in the user record in the server database.
3. When performing each security transaction (any transaction in which the user is logged in), compare the cookie message digest with the digest stored in the server database. If the comparison fails,
direct the user to Login interface.
4. If the check in step 3 passes, then check whether the elapsed time between the current time and the login time exceeds the allowed time length. If the user has timed out, the user will be directed to the login
interface.
5. If steps 3 and 4 are passed, then reset the login time to the current time and allow the transaction to occur. Most of those secure sites that require you to log in may use a method similar to the one introduced here
.
Composition of Cookies
Cookies were originally designed for CGI programming. However, we can also use Javascript scripts to manipulate cookies. In this article, we will demonstrate how to use Javascript script
to manipulate cookies. (If there is demand, I may introduce how to use Perl for cookie management in a future article. But if you really can’t wait, then I will teach you now:
Take a closer look at CGI.pm. In this CGI package there are A cookie() function can be used to create cookies. However, let us first introduce the nature of cookies.
In Javascript, a cookie is actually a string attribute when you read it. value, you will get a string containing the names and values of all cookies
used by the current WEB page. In addition to the two attributes of name and value, each cookie also has four attributes: expires expiration time, path, domain,
and secure security.Expires – Expiration time. Specify cookie lifetime. Specifically, the value is the expiration date. If you want the cookie to last longer than the current browser session, you must use this attribute
. When the expiration date has passed, the browser can delete the cookie file without any impact.
Path – path. Specify the WEB page associated with the cookie. The value can be a directory or a path. If http://www.zdnet.com/devhead/index.html creates a
cookie, then all pages in the http://www.zdnet.com/devhead/ directory, and any pages under the directory This cookie can be accessed by pages in subdirectories. This means
that any page in http://www.zdnet.com/devhead/stories/articles can access the cookie created by http://www.zdnet.com/devhead/index.html.
However, what should we do if http://www.zdnet.com/zdnn/ needs to access the cookies set by http://www.zdnet.com/devhead/index.html? At this time, we need to set the path attribute of
cookies to "/". When specifying a path, all WEB pages that come from the same server and have the same path in the URL can share cookies. Now look at another
example: If you want http://www.zdnet.com/devhead/filters/ and http://www.zdnet.com/devhead/stories/ to share cookies, you need to set the path to "
/devhead".
Domain – domain. Specify the associated WEB server or domain. The value is the domain name, such as zdnet.com. This is an extension of the path attribute. What if we want
catalog.mycompany.com to be able to access the cookies set by shoppingcart.mycompany.com? We can set the domain attribute to "mycompany.com"
and set the path attribute to " /". FYI: You cannot set the cookies domain attribute to a value different from the domain of the server that sets it.
Secure – safe. Specifies how cookie values are passed between the user and the WEB server over the network. The value of this attribute is either "secure" or empty. By default, this attribute
is empty, which means an insecure HTTP connection is used to transfer data. If a cookie is marked as secure, then data is transferred between it and the WEB server through HTTPS or other secure protocols
. However, setting the secure attribute does not mean that others cannot see the cookies saved locally on your machine. In other words, setting the cookie to secure only ensures that the data transmission process between the cookie and the WEB
server is encrypted, and the cookie file stored locally is not encrypted. If you want local cookies to be encrypted, you have to encrypt the data yourself.
Manipulating Cookies
Remember, a cookie is just a string attribute of the document. To save cookies, just create a string in the format name=

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version
Chinese version, very easy to use