PHP $ _SESSION多个用户同时 [英] PHP $_SESSION for multiple users at once

查看:232
本文介绍了PHP $ _SESSION多个用户同时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解一下$ _SESSION数组是如何工作的。如果我有很多使用我的网站,我需要为每个用户设置一个子阵列的用户?比如现在我有

I'm wondering about how the $_SESSION array works. If I have a lot of users using my site do I need to set a subarray for each user? For instance right now I have

$_SESSION['userid'] = $userid;
$_SESSION['sessionid'] = $sessionid;
$_SESSION['ipaddress'] = $ipaddress;

但为了应付更多的用户,我需要做一个多维数组?

but in order to cope with more users do I need to make a multidimensional array?

$_SESSION[$userid]['sessionid'] = $sessionid;
$_SESSION[$userid]['ipaddress'] = $ipaddress;

时的$ _SESSION全球每个客户端的处理或只是整体?将有$ _SESSION ['用户ID']在登录设置踢previous用户并instate用户最新登录?

Is the $_SESSION global handled per client or just overall? Will having $_SESSION['userid'] set on login kick the previous user out and instate the latest logged in user?

推荐答案

没有。有一个单独的 $ _ SESSION 为每个用户创建。这一切都是由服务器完成的,您不必担心。在编写code,治疗 $ _ SESSION 好像有在网站上只有一个用户。

No. There is a seperate $_SESSION created for each user. This is all done by the server, you don't have to worry about it. When writing your code, treat the $_SESSION as if there was only one user on the site.

编辑:其实,就想着它,它是一个很好的问题要问。这是好事,问这些各种各样的问题,这意味着你是认真思考如何你的code的真正的作品的。不断地问这些事情,并保持测试。我有一种感觉,有一天你会写一些惊人的code。

Actually, on thinking about it, it is a very good question to ask. It is good to ask these sorts of questions, it means you are seriously thinking about how your code truly works. Keep asking these things, and keep testing. I have a feeling that one day you will be writing some amazing code.

所以,关于这一点,这里是从阿帕奇网站的一些信息:

So on that note, here is some info from the apache site:

什么是会话?

在会议界面的核心是由跨浏览器的请求访问键和值对的表。这些对可以被设置为任何有效的字符串,根据需要由应用程序利用会话。

At the core of the session interface is a table of key and value pairs that are made accessible across browser requests. These pairs can be set to any valid string, as needed by the application making use of the session.

保留在服务器上的会话

Apache可以被配置成跟踪每次存储服务器的一个特定的服务器或一组用户的会话。此功能类似于典型的应用服务器提供的会话。

Apache can be configured to keep track of per user sessions stored on a particular server or group of servers. This functionality is similar to the sessions available in typical application servers.

如果配置,会话是通过使用存储的cookie的内部,或从嵌入URL查询字符串内的参数中提取的会话ID的跟踪,如在典型的GET请求中。

If configured, sessions are tracked through the use of a session ID that is stored inside a cookie, or extracted from the parameters embedded within the URL query string, as found in a typical GET request.

和来自 PHP文档的访问

在PHP中的会话支持由一种方法来用于之后的preserve某些数据。这使您可以建立更多的定制化的应用并提高网站的吸引力。

Session support in PHP consists of a way to preserve certain data across subsequent accesses. This enables you to build more customized applications and increase the appeal of your web site.

一个访问者访问你的网站被分配一个唯一的ID,即所谓的会话ID。此操作可以存储在用户侧的cookie或在URL被传播

A visitor accessing your web site is assigned a unique id, the so-called session id. This is either stored in a cookie on the user side or is propagated in the URL.

会话支持允许你存储$ _SESSION全局数组中的请求之间的数据。当访问者访问您的网站,PHP会自动(如果session.auto_start被设为1)或在用户请求(显式地在session_start()或隐式了session_register())是否特定的会话ID已与请求一起发送。如果是这种情况,在现有保存的环境中重新创建。

The session support allows you to store data between requests in the $_SESSION superglobal array. When a visitor accesses your site, PHP will check automatically (if session.auto_start is set to 1) or on your request (explicitly through session_start() or implicitly through session_register()) whether a specific session id has been sent with the request. If this is the case, the prior saved environment is recreated.

这篇关于PHP $ _SESSION多个用户同时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆