将PHP会话数据存储在数据库中的最佳做法是什么?

时间:2022-08-08 16:59:40

I have developed a web application that uses a web server and database hosted by a web host (on the ground) and a server running on Amazon Web Services EC2. Both servers may be used by a user during a session and both will need to know some session information about a user. I don't want to POST the information that is needed by both servers because I dont want it to be visible to browsers / Firebug etc. So I need my session data to persist across servers. And I think that this means that the best option is to store all / some of the data that I need in the database rather than in a session. The easiest thing to do seems to be to keep the sessions but to POST the session_id between servers and use this as the key to lookup the data I need from a 'user_session_data' table in the database.

我开发了一个Web应用程序,它使用由Web主机(在地面上)和在Amazon Web Services EC2上运行的服务器托管的Web服务器和数据库。两个服务器可以在会话期间由用户使用,并且两者都需要知道关于用户的一些会话信息。我不想发布两个服务器所需的信息,因为我不希望它对浏览器/ Firebug等可见。所以我需要我的会话数据在服务器上保持不变。我认为这意味着最好的选择是在数据库中而不是在会话中存储我需要的所有/部分数据。最简单的做法似乎是保持会话,但是在服务器之间POST session_id,并使用它作为从数据库中的'user_session_data'表中查找我需要的数据的关键。

I have looked at Tony Marston's article "Saving PHP Session Data to a database" - should I use this or will a table with the session data that I need and session_id as key suffice? What would be the downside of creating my own table and set of methods for storing the data I need in the database?

我查看了Tony Marston的文章“将PHP会话数据保存到数据库” - 我应该使用它还是将表格与我需要的会话数据和session_id作为关键就足够了?创建我自己的表和一组用于存储数据库中所需数据的方法会有什么缺点?

1 个解决方案

#1


2  

If transfer speed and response times between EC2 and the database server are good enough, I see no problem with storing the session data as described, and passing the session_id along when transfering the user to a different server.

如果EC2和数据库服务器之间的传输速度和响应时间足够好,我认为存储会话数据没有问题,并且在将用户传输到其他服务器时传递session_id。

--

-

Storing session data in a database is pretty common practice. "Storing data on a session" does not imply any actual storage method – creating files on disk is simply PHP's default setting, since it doesn't require any setup.

将会话数据存储在数据库中是很常见的做法。 “在会话上存储数据”并不意味着任何实际的存储方法 - 在磁盘上创建文件只是PHP的默认设置,因为它不需要任何设置。

#1


2  

If transfer speed and response times between EC2 and the database server are good enough, I see no problem with storing the session data as described, and passing the session_id along when transfering the user to a different server.

如果EC2和数据库服务器之间的传输速度和响应时间足够好,我认为存储会话数据没有问题,并且在将用户传输到其他服务器时传递session_id。

--

-

Storing session data in a database is pretty common practice. "Storing data on a session" does not imply any actual storage method – creating files on disk is simply PHP's default setting, since it doesn't require any setup.

将会话数据存储在数据库中是很常见的做法。 “在会话上存储数据”并不意味着任何实际的存储方法 - 在磁盘上创建文件只是PHP的默认设置,因为它不需要任何设置。