无法更改 php 会话 cookie 名称

发布于 2024-09-28 22:18:37 字数 669 浏览 0 评论 0原文

我将现有且成功运行的站点复制到新的开发服务器。

现在新服务器上的登录已损坏,我追踪到虽然会话cookie已重命名……

ini_set('session.name', 'DOMAIN1');

但浏览器仍将会话cookie存储为PHPSESSID。

当我从新服务器上的应用程序中删除上述行时,登录再次正常。但这不是一个好的解决方案,因为另一个应用程序也使用这个名称下的 PHPSESSID。

我更愿意找到奇怪行为的原因,而不是使用解决方法。如果我不解决它,它可能会在其他地方咬我。

也许这已经足以让某人给我提示了。如果没有,哪些信息会有用?

这台机器是一个非常裸露和基本的ubuntu 8.04服务器,我用aptitude安装了apache2、mysql和php5。我还更新了 lokales 和时区。

解决方案:

我用已接受答案中的代码替换了上面的行......

if(ini_set('session.name', 'DOMAIN1') === false || !session_name('DOMAIN1'))
{
    die('Unable to set sesssion scope');
}

并且登录现在可以在新服务器上运行。

I copied an existing and successfully running site to a new development server.

The login on the new server is now broken, and I tracked it down to the fact that although the session cookie is renamed ...

ini_set('session.name', 'DOMAIN1');

... the browser keeps storing the sesssion cookie as PHPSESSID.

When I remove the above line from the application on the new server, the login works again. But this is not a good solution, because another application also uses PHPSESSID under this name.

And I would prefer to find the reason for the strange behaviour instead of using a workaround. If I don't fix it it could bite me somewhere else.

Maybe this is already enough information for someone to give me a hint. If not, what information would be useful?

This machine was a very naked and basic ubuntu 8.04 server, and I installed apache2, mysql and php5 with aptitude. I also updated lokales and the timezone.

Solution:

I replaced the line above with this code from from the accepted answer ...

if(ini_set('session.name', 'DOMAIN1') === false || !session_name('DOMAIN1'))
{
    die('Unable to set sesssion scope');
}

... and the login now works on the new server.

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

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

发布评论

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

评论(1

反目相谮 2024-10-05 22:18:37

有时 ini_set 会播放,但无法正确设置 ini 值,可能与权限有关。

下面的内容并不能完全解决 ini_set 的问题,如果有人知道 ini_set 在某些类型的主机上不起作用的原因,请分享!

尝试以下操作:

<?
if(ini_set('session.name', 'DOMAIN1') === false || !session_name('DOMAIN1'))
{
    die('Unable to set sesssion scope');
}

phpinfo();
?>

或者您可以使用 session_name() 来设置它,并且我总是建议您不要只运行函数并希望始终在 if 语句中检查并为最坏的情况做好准备,那就是您的应用程序变得可靠且不易出错的时候。

Sometimes ini_set plays up and is unable to set the ini values correctly, might be down to permissions.

the below does not fully resolve the issue with ini_set, and if anyone knows the reason(s) why ini_set does not work on some type's of host, then please share!

Try the following:

<?
if(ini_set('session.name', 'DOMAIN1') === false || !session_name('DOMAIN1'))
{
    die('Unable to set sesssion scope');
}

phpinfo();
?>

alternatively you can just use session_name() to set it, and ill always advise you not to just run functions and hope the always check the in an if statement and prepare for the worst case scenario, thats when your application becomes reliable and less error_prone.

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