简体   繁体   English

会话如何跟踪多个用户

[英]How do sessions track more than one user

Sorry this is probably a beginners question. 抱歉,这可能是一个初学者的问题。 If I'm using $_SESSION variables how does the server track more than one user/reference them eg Say John has logged on $_SESSION['username']="John" how would system reference Peter and James who have also logged on because you cannot have $_SESSION['username']="Peter" and $_SESSION['username']="James" as they would over write each other? 如果我使用$_SESSION变量,服务器如何跟踪多个用户/引用它们,例如,说约翰登录了$_SESSION['username']="John" ,系统将如何引用也登录的Peter和James,因为您不能让$_SESSION['username']="Peter"$_SESSION['username']="James"互相覆盖?

I'm probably missing something simple here. 我可能在这里缺少一些简单的东西。

@user2976086 @ user2976086

$_SESSION is precisely what keeps users apart for the php server. $ _SESSION正是使用户与php服务器区分开的原因。 Each time session_start is called, php server creates a new client session(if such is not already started) which usually results in a cookie named PHPSESSID being created in your browser. 每次调用session_start时,php服务器都会创建一个新的客户端会话(如果尚未启动),通常会在浏览器中创建一个名为PHPSESSID的cookie。 On server side, the php server creates, let's say, a unique $_SESSION array for each unique session id(stored in the cookie, only one per browser). 在服务器端,php服务器为每个唯一的会话ID(存储在cookie中,每个浏览器仅一个)创建一个唯一的$ _SESSION数组。 That is why you can only log in with one user per browser(you can log in with 2 accounts simultaneously to most sites using firefox and chrome for example as a cookie is created for each browser). 这就是每个浏览器只能用一个用户登录的原因(例如,当为每个浏览器创建cookie时,您可以使用2个帐户同时使用firefox和chrome登录大多数站点)。 That is why u can not "overwrite" $_SESSION['username'] with different user unless you log out in that browser window causing session_destroy to be called or remove the cookie containing sessionid for current user. 这就是为什么您不能用其他用户“覆盖” $ _SESSION ['用户名']的原因,除非您在浏览器窗口中注销导致session_destroy被调用或删除包含当前用户sessionID的cookie。

try reading: http://www.php.net/manual/en/session.security.php 尝试阅读: http : //www.php.net/manual/en/session.security.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM