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

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

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),
