Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 关于SESSION的一点疑问

关于SESSION的一点疑问

Jun 23, 2016 pm 01:46 PM

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 分钟就要重新登录,那不也太不友好了吗?

并不是全部session存储 

需要走服务 后台用其他语言实现  有内存缓存   最终落地是在数据库

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

Customizing/Extending Frameworks: How to add custom functionality. Customizing/Extending Frameworks: How to add custom functionality. Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

See all articles