search
HomeBackend DevelopmentPHP Tutorial请教session的一个疑问

用户A在北京登录一个网站,生成$_session['success']=1;

用户B在上海登录同一个网站,生成$_session['success']=2;

这两个session值会不会有冲突和影响啊?B用户的值会不会覆盖掉A用户的啊,

session_id 和 PHPSESSID 是一回事吗?

这种问题是不是可幼稚,可是一直让我很困惑啊,


回复讨论(解决方案)

sessionid 与浏览器绑定,不同的浏览器进程有不同的 sessionid。与浏览器在什么地方无关
sessionid 由 web 系统维护,不会发生重复。之所以说是 web 系统 是因为并不只是 php 有 session
PHPSESSID 是 sessioid 的名字(识别标志)session_id 是他的值

你能理解$_GET这个东西吗,跟$_SESSION是一个道理

用户A在北京登录一个网站,生成$_session['success']=1;

用户B在上海登录同一个网站,生成$_session['success']=2;

这两个session值会不会有冲突和影响啊?B用户的值会不会覆盖掉A用户的啊,



那这个问题呢?

不会有重复的,其实你不需要去考虑这些的,你就当不可能重复就可以了,sessionid一般是用cookie传递的,保存在客户端浏览器上,PHPSESSID是session_id的名字

好像是有点幼稚哈哈哈!孩纸,session是根据不同客户端(浏览器)生成的,互不影响,别说是不同城市,你在同一台电脑上面用两个不同浏览器访问同一个网站,生成的同一个session名称的值也是不一样的

用户A在北京登录一个网站,生成$_session['success']=1;

用户B在上海登录同一个网站,生成$_session['success']=2;

这两个session值会不会有冲突和影响啊?B用户的值会不会覆盖掉A用户的啊,

session_id 和 PHPSESSID 是一回事吗?

这种问题是不是可幼稚,可是一直让我很困惑啊,



不会,如果会就天下大乱了。

session_id是与浏览器绑定的,唯一。是一次会话。
PHPSESSID 是session_id的名。

使用session_start()调用session,服务器端在生成session文件的同时,生成session ID哈希值和默认值为PHPSESSID的session name,并向客户端发送变量为(默认的是)PHPSESSID(session name),值为一个128位的哈希值。服务器端将通过该cookie与客户端进行交互.。

我测试了一下,终于明白了,

session是唯一的,一个用户,一个完全独立的session进程,因为手册和别的地方总是强调sesssion_id是唯一的,所以我一直搞不明白,如果是session设置的其它值,会不会冲突,比如 $_SESSION['logined']=true 

其实就是一个用户,对应一个完全独立的session进程,服务器上无论有多少个访客生成的session进程,都是互相独立,互不干涉的。

就像服务器一样,无论上面放了多少个虚拟主机,都是独立的,互不冲突,他们之间并没有什么关系的。


Statement
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
PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

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

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

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.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

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

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

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

How to make PHP applications fasterHow to make PHP applications fasterMay 12, 2025 am 12:12 AM

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

PHP Performance Optimization Checklist: Improve Speed NowPHP Performance Optimization Checklist: Improve Speed NowMay 12, 2025 am 12:07 AM

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

PHP Dependency Injection: Improve Code TestabilityPHP Dependency Injection: Improve Code TestabilityMay 12, 2025 am 12:03 AM

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.

PHP Performance Optimization: Database Query OptimizationPHP Performance Optimization: Database Query OptimizationMay 12, 2025 am 12:02 AM

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

See all articles

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

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MantisBT

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.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment