1. Shopping Cart Function
Shopping cart is an important function in the Online Shopping System, which is similar to the shopping process in real stores. In a network environment, users may jump between different pages of a website in a network store to buy their favorite items. Finally, all the items selected are placed in the shopping cart and settled at the payment desk. The server tracks the actions of each user to ensure that each item has its own ownership at checkout. The shopping cart function should include the following items:
2. Add the books to the shopping cart to order the books;
2. Delete the books subscribed to in the shopping cart;
2. Modify the order quantity of a book in the shopping cart;
2. Clear the shopping cart;
2. display the list, quantity, and price of books in the shopping cart;
The key to implementing a shopping cart is that the server identifies every user and maintains contact with them. However, HTTP is a "stateless" protocol, so the server cannot remember who is buying a book. when the product is added to the shopping cart, the server does not know what was originally in the shopping cart, which makes it impossible for the user to "carry with him" when jumping between pages, which makes it difficult to implement the shopping cart.
2 Development Status
Currently, the shopping cart is implemented through cookies, sessions, or databases. The following describes their mechanisms and functions.
2. 1. Cookie
Cookie is a piece of information that is generated by the server and stored on the client. It defines a mechanism for the Web server to store and return information on the client. The cookie file contains the domain, path, lifetime, and variable values set by the server. When a user accesses the same web server in the future, the browser will send the cookie to the server as it is. By allowing the server to read the information originally stored on the client, the website can provide a series of convenience for viewers, for example, when a user is identified during an online transaction and has low security requirements, users are not allowed to repeatedly enter their names and passwords, customize the portal's home page, and place advertisements in a targeted manner. The cookie feature greatly extends Web applications.ProgramYou can not only establish the connection between the server and the client, because the cookie can be customized by the server, so you can also store the cookie value generated by the shopping information on the client to implement the shopping cart function. Cookie-based session or shopping cart between the server and the browser has the following features;
2. The cookie is stored on the client and occupies a small amount of resources. The Browser allows 300 cookies to be stored. The size of each cookie is 4 kb, which is sufficient to meet the requirements of the shopping cart, it also reduces the load on the server;
2. Cookies are built in the browser for ease of use. Even if you accidentally close the browser window, the information in the shopping cart will not be lost as long as it is within the validity period defined by the cookie;
2. Cookies are not executable files, so they are not executed in any way, and therefore do not cause viruses or attack users' systems.
2. The cookie-based shopping cart requires that the user's browser support and set it to enable cookies; otherwise, the shopping cart becomes invalid;
2. There is a debate about Cookie infringement on the privacy of visitors. Therefore, some users will disable the cookie function of the local machine.
2. 2 Session
Session is another way to implement shopping cart. Session provides the ability to save and track user status information so that the variables and objects defined by the current user in the session can be shared between pages, however, it cannot be accessed by other users in the application. The most important difference between session and cookie is that session stores the private information of the user during the session on the server, improving the security. After the server generates a session, the client generates a sessionid identification number and stores it on the client to maintain synchronization with the server. This sessionid is read-only. If the cookie function is disabled on the client, the session will be transferred between pages by adding parameters to the URL or implicitly submitting in the form. Therefore, session implementation is more secure and effective for user management.
Similarly, the use of session can also implement the shopping cart, which is characterized:
2. The session maintains synchronization with the client using a new mechanism and does not rely on the client settings.
2. Compared with cookies, session information is stored on the server, which is more secure. Therefore, information such as identity tags and shopping can be stored in the session.
2. Sessions occupy server resources and increase server load. When many concurrent users exist, a large number of sessions are generated, which affects server performance.
2. Because session information is more sensitive and stored on the server as files, there are still security risks.
2.3. Database Integration
This is a common mode. In this mode, databases store shopping information, and session or cookie is used to track users. This method has the following features:
2. The database and cookie are respectively responsible for recording data and maintaining sessions. They can leverage their respective advantages to improve security and server performance;
2. A connection to the database must be established for each shopping activity until the table operation is complete. When there are many concurrent users, the database performance will be affected. Therefore, this puts forward higher requirements on the database performance;
2. Cookie persistence depends on client support;
3. Existing Problems
Although cookies can be used to implement shopping cart, they must be supported by browsers. In addition, they are stored on the client and can be easily obtained. Therefore, this limits the storage of more information, more important information. Therefore, cookies are generally used to maintain sessions with servers. For example, the largest Dangdang online bookstore in China uses cookies to maintain contact with customers, however, the biggest disadvantage of this method is that if the client does not support cookies, the shopping cart will become invalid.
Session can maintain a session with both parties, and the client settings can be ignored. It has been widely used in shopping cart technology. However, the file attributes of the session leave security risks.
although the database method solves the above problems to a certain extent, the preceding example shows that frequent operations on database tables are involved in this shopping process, in particular, every time a user buys a product, they need to connect to the database. When many users, the load on servers and databases is increased.