关于SESSION的1点疑问
关于SESSION的一点疑问
SESSION是放在服务器上的,服务器会给用户一个SESSIONID,用户靠着SESSIONID去访问,一次会话结束后SESSIONID就没有了。。用户自然就找不到原先的SESSION文件了。
------------------------------------------------------------------------------------------------------------------------------
那我现在有个问题。。像类似淘宝或者京东的购物车系统怎么用SESSION实现的?
1.因为如果用SESSION,关闭浏览器后数据就找不到了,第二次再看岂不是购物车就是空的?
2.如果用COOKIE保存在客户端那我换台电脑岂不是购物车也是空的?
3.如果放在数据库里那每个用户访问都是调用数据库查询那服务器压力岂不是太大了?
4.SESSION在服务器默认保存的时间是1440秒,如果我没理解错的话,这个时间没用啊,因为关闭浏览器你就找不到SESSION文件了,第二次也没办法调用,设置成5分钟岂不是更好?
--------------------------------------------------------------------------------------------------------------------------------
小弟初学PHP有可能对SESSION理解不是很正确,有点偏激,希望各位不吝赐教,多多指正!
------解决思路----------------------
1、2、3、都是用数据库的,把用户id设成索引很快,而且人家也不是一台服务器。照你这样说,每次登录,还要查数据库呢,压力也很大咯?!
4、你说的1440秒是用户停留在一个页面的时间,过了这个时间再到其他页面去,其他页面就没有session的信息了
------解决思路----------------------
没有网购过,不知道关闭浏览器后,购物车数据是否还存在
假定是存在的话,那么他就是保存在数据库里的,并以用户名作为唯一识别标志
为什么把数据放到数据库里就觉得服务器压力大了,而放在文件里就不那么感觉呢?
显然这是一个认知的误区,要知道表文件也是文件呀
session 的 1440秒,是指 session 的最短存留时间。即最后一次访问的 1440秒后才可以删除
为什么是 1440秒而不是更短,这是一个统计意义上的量。在操作过程中临时有事(抽烟、喝水、接电话...)一般不会超过 24 分钟,如果暂停 5 分钟就要重新登录,那不也太不友好了吗?

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

In iOS 17, Apple introduced several new privacy and security features to its mobile operating system, one of which is the ability to require two-step authentication for private browsing tabs in Safari. Here's how it works and how to turn it off. On an iPhone or iPad running iOS 17 or iPadOS 17, Apple's browser now requires Face ID/Touch ID authentication or a passcode if you have any Private Browsing tab open in Safari and then exit the session or app to access them again. In other words, if someone gets their hands on your iPhone or iPad while it's unlocked, they still won't be able to view your privacy without knowing your passcode

The famous activation script MAS2.2 version supports digital activation again. The method originated from @asdcorp and the team. The MAS author calls it HWID2. Download gatherosstate.exe (not original, modified) from https://github.com/massgravel/Microsoft-Activation-Scripts, run it with parameters, and generate GenuineTicket.xml. First take a look at the original method: gatherosstate.exePfn=xxxxxxx;DownlevelGenuineState=1 and then compare with the latest method: gatheros

Session failure is usually caused by the session lifetime expiration or server shutdown. The solutions: 1. Extend the lifetime of the session; 2. Use persistent storage; 3. Use cookies; 4. Update the session asynchronously; 5. Use session management middleware.

Cookies are usually stored in the cookie folder of the browser. Cookie files in the browser are usually stored in binary or SQLite format. If you open the cookie file directly, you may see some garbled or unreadable content, so it is best to use Use the cookie management interface provided by your browser to view and manage cookies.

Cookies on your computer are stored in specific locations on your browser, depending on the browser and operating system used: 1. Google Chrome, stored in C:\Users\YourUsername\AppData\Local\Google\Chrome\User Data\Default \Cookies etc.

Solution to the cross-domain problem of PHPSession In the development of front-end and back-end separation, cross-domain requests have become the norm. When dealing with cross-domain issues, we usually involve the use and management of sessions. However, due to browser origin policy restrictions, sessions cannot be shared by default across domains. In order to solve this problem, we need to use some techniques and methods to achieve cross-domain sharing of sessions. 1. The most common use of cookies to share sessions across domains
