PHP:SESSIONS的替代品

我有一个非常依赖会话变量的PHP应用程序。 登录后,用户将被重定向到执行代码的页面,以根据用户的身份设置会话变量的负载。 应用程序使用来自不同来源的数据,会话用于存储ID号以查询数据库。</ p>

因此,当用户转到将向其资产管理系统查询其ID的页面时 通过会话调用该特定数据库。</ p>

我最近遇到了很多会话变量问题。 有时在应用程序的生命周期内只创建一个会话文件,有时每个会话请求都会产生一个新的会话ID(仍然无法找到原因!)。 </ p>

我的问题是这个。 是否有替代使用会话变量? 像全局或其他方式一样?</ p>

我在这里有一个关于我的会话问题的问题 - 未维护PHP会话变量 </ p>
</ div>

展开原文

原文

I have a PHP application that relies on session variables quite a lot. After login the user get redirected to a page that executes code to set up a load of session variables depending on who the user is. The application is using data from different sources and the sessions are used to store ID numbers to query the databases.

So when the user goes to a page that will query their asset management system their ID for that particular database is called via the session.

I've had a LOT of problems with session variables recently. Sometimes only one session file is created during the lifetime of the app, and sometimes each session request results in a new session id (still haven't managed to find out why!).

My question is this. Is there an alternative to using session variables for this? Like globals or some other way?

I have a question open about my session problem here - PHP session variables not being maintaned

dongzongzhi6953
dongzongzhi6953 我看到的一点在这里没有提到......如果您最近安装了任何依赖于交响乐的组件并且它包含了“会话管理”系统,那很可能是您问题的根源。
大约 2 年之前 回复

7个回答



另一种方法是将会话数据存储在数据库中,为用户提供带有session_id的cookie。 这样可以让您更好地控制会话。</ p>
</ div>

展开原文

原文

Another alternative is to store session data in database in give user a cookie with your session_id. That will give you more control around sessions.

dtip91401
dtip91401 是的,逻辑是一样的,但是,通过将会话和会话数据保持在可控和可扩展的位置,您可以完全控制管理会话。
接近 7 年之前 回复
doushu8260
doushu8260 这......这就是会话通常如何工作,服务器只存储由php自动生成的特定会话令牌。 所以请注意,从这个角度来看,没有真正获得任何东西。
接近 7 年之前 回复
douti9286
douti9286 实际上这是一个cookie问题。 在一个页面上创建一个cookie,导航到另一个页面,cookie就消失了
接近 10 年之前 回复
doushuo8677
doushuo8677 这听起来不错,但我遇到的问题是,每个会话请求都会生成一个新的会话ID。 因此,如果我给他们一个会话ID,它可能会改变或被覆盖
接近 10 年之前 回复



不,因为每个用户会话都应该有一个值,所以需要某种会话机制。 PHP的会话很好。 您可能只需要正确配置它以满足您的需求。</ p>
</ div>

展开原文

原文

No, since each user session should have its one values, you need some kind of session mechanism. And PHP’s session is fine for that. You probably just need to configure it properly to meet your needs.



你可以使用其他一些“会话”解决方案,但这需要你做更多的管道工作。</ p>

例如,您可以使用基于网址的会话,其中网站生成的每个网址都包含一个会话ID。 这通常是网站的重大重新设计,并且唯一需要的时间是您需要在多个域上进行相同的会话,或者如果您希望在浏览器中的不同窗口中运行不同的会话,则需要相同的计算机。</ p >

但是在你的情况下,我会检查为什么会话被破坏,可能是一个配置问题,或者你还有其他东西搞砸了会话文件。</ p>

I 从来没有遇到任何PHP会话的麻烦,他们只是工作;)</ p>
</ div>

展开原文

原文

You could use some other "session" solution but that requires you to do more of the plumbing.

For example, you could use url based sessions where every url the site generates includes a sessionid. This is usually a major redesign of the site and the only time it is required is if you need to have the same session over multiple domains OR if you like to have the same computer running different sessions in different windows in the browser.

But in your case I would check why the sessions are broken, its probably a configuration issue or you have someting else that screws up the session files.

I have never had any trouble with PHP sessions, they just work ;)



Sessions似乎是正确的解决方案。
一般会话的工作方式如下:
会话对象在服务器上创建并分配给 ID。 id通过cookie发送到浏览器并根据浏览器的请求发送到服务器,从而使服务器能够从内存中获取正确的会话对象。</ p>

您可能希望查看 在您的会话配置方式。 如果你继续“失去”会话,一个可能的原因可能是你在子域之间“跳跃”并且只为一个子域设置了会话cookie。 另一个原因可能是您的会话过期时间太短。</ p>
</ div>

展开原文

原文

Sessions seem like the right solution for this. Generally sessions work like this: A session object is created on the server and assigned an id. The id is sent to the browser in a cookie and sent to the server with request of the browser, thus enabling the server to fetch the correct session object from memory.

You may want to look at how your session is configured. If you keep "loosing" sessions, one possible cause could be that you are "jumping" between subdomains and have the session cookie set for only one subdomain. Another cause could be that you have a too low expiry on your session.

dongzhang2150
dongzhang2150 感谢回复我有一个关于会话问题的问题在这里打开 - stackoverflow.com/questions/4358525 / ...
接近 10 年之前 回复



Cookie实际上不是替代品,特别是用于登录时,因为它们可以由用户更改,而对于会话而言 在他们的计算机上存储一个包含识别哈希的cookie,修改它不会让它们走得太远。</ p>

无论如何,会话工作</ em>。 毫无疑问,您的问题是实施问题。 我建议您花一些时间进行调试和测试,因为实现一种替代方法会导致代码变得非常复杂 - 而且您不想这样做,因为会话已经导致您遇到麻烦。</ p>
</ DIV>

展开原文

原文

Cookies aren't really an alternative, in particular when used for logins, since they can be changed by the user, while for sessions just store a cookie containing an identifying hash on their computer, and modifying it won't get them very far.

Anyway, sessions work. Your problem is, with no doubt, an implementation problem. I suggest you spend some time debugging and testing, since implementing an alternative method will lead to an incredibly more complex code - and you don't want to do it, since sessions are causing you trouble already.



对于在每个请求中重新创建的会话,您应该尝试调试服务器发送给您的cookie。
cookies检查cookie域是否正确(并检查cookie路径)。</ p>

要调试cookie,您可以使用Web开发人员工具栏显示页面加载后哪些cookie处于活动状态 。 但最好的工具是Live Http标题,检查服务器发送的真实标题,你会发现真正的cookie内容,如果cookie域中存在不匹配(例如 - 但大部分时间都是这样)你的浏览器 不会为您的网站存储此cookie。</ p>

如果您的浏览器忽略cookie,您请求PHP的下一页构建另一个会话等。</ p>

如果 你不能让你的cooki系统工作你可以跟踪在PHP中跟踪会话Id的旧方法,它使用PHPSESSID的永久get和/或post参数。
你需要在你的PHP编译中使用--enable-rans-id (在phpinfo页面上查看) http://www.php.net/manual /en/session.idpassing.php </ p>
</ div>

展开原文

原文

For your sessions which are re-created at each request you should try to debug the cookies send to you by the server. In theses cookies check that the cookie domain is the right one (and check cookie path as well).

To debug cookies you could use the web developer toolbar to show which cookies are active after the page load. But the best tool is Live Http headers, check the real headers send by the server, there you'll find the real cookie content, and if there's a mismatch in the cookie domain (for example -- but most time it's that) your browser will not store this cookie for your website.

If your browser ignore a cookie, next page you request PHP builds another session, etc.

If you cannot get you cooki system to work you can track the old way of tracking sessions Id in PHP, which was using a permanent get and/or post parameter with the PHPSESSID. You need --enable-rans-id on your PHP compilation (check it on a phpinfo page) http://www.php.net/manual/en/session.idpassing.php



会话的替代方案是cookie(实际上,会话通常使用cookie实现)。 但是,只有在您想存储小</ em>数据量时才应使用cookie。</ p>
</ div>

展开原文

原文

The alternative to sessions is cookies (in fact, sessions are usually implemented using cookies). But cookies should only be used if you want to store small amounts of data.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问