PHP 4 中的 session_start()

发布于 2024-12-21 19:40:21 字数 536 浏览 0 评论 0原文

我一直认为我是最不幸的人,因为我必须维护别人写的非常糟糕的代码。但在浏览了一些论坛后,我意识到我并不孤单。

这段代码是我开始在这里工作之前编写的,现在我正在维护它。我总是要求我们分配时间重写代码,但没人关心。

我要问的问题,你可以评论说这绝对是可怕的,但重写整个代码不是一个选择。

这是场景。

整个网站是用PHP 4编写的(60%的网站都在index.php中,不知道为什么),所以时不时会有session_start()。因此,会话会非常频繁地重置,并且用于注销用户。我继续注释掉 session_start()。当用户访问网站时,它会停止注销用户。现在出现了一些新问题。

我通过注释 session_start() 做错了什么吗?

编辑: 我看到了有关 session_start 的文档,可能是我没有添加一些有问题的附加信息。我用谷歌搜索“会话大小限制 PHP”,以下是链接。 stackoverflow.com/questions/217420/ideal-php-session-size。那么如果会话中数据过多会发生什么情况呢? – 用户110093

I always think that I am the unluckiest guy, because I have to maintain very horrible code written by some one else. But after going through some of the forums, I realized I am not alone.

This code was written before I started working here, now I am maintaining it. I always keep asking that we should allocate time to rewrite the code, but no one cares.

The question I am about to ask, you can comment that it is absolutely horrible, but rewriting the whole code is not an option.

Here is the scenario.

The whole website is written in PHP 4 (60% of website is in index.php, don't know why), so every now and then there is session_start(). Due to that, the session gets reset very frequently and it used to log out the user. I went ahead and commented out session_start(). It stopped logging out the user when he is in the website. Now there are some new issues.

Did I do something wrong by commenting the session_start()?

EDIT:
I saw documentation about session_start, may be I did not add some additional information in question. I did google search "session size limit PHP" the following is the link. stackoverflow.com/questions/217420/ideal-php-session-size. So what happens if there is too much data in the session? – user110093

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

聆听风音 2024-12-28 19:40:21

来自 php 文档

session_start() 根据通过 GET 或 POST 请求传递的会话标识符或通过 cookie 传递的会话标识符创建会话或恢复当前会话。

因此,您在下面描述的情况不应该发生:

所以时不时就会有session_start()。由于会话重置非常频繁,并且曾经导致用户注销。

如果我是你,我会更深入地研究并找出会话重置的原因。 session_start() 不应该是这个问题的根源。

From the php documentation

session_start() creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie.

So what you are describing in the following should not be happening:

so every now and then there is session_start(). Due to that the session gets reset very frequently and it used to log out the user.

If I were you, I would delve deeper and find out the reason why sessions are reset. session_start() should not be the root of this problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文