无法更改PHP会话cookie名称 [英] Cannot change php session cookie name

查看:283
本文介绍了无法更改PHP会话cookie名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我复制一个现有的和成功运行的网站到一个新的开发服务器。

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

在新服务器上登录,现在坏了,我跟踪它到一个事实,即尽管会话cookie被重命名...

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');

...浏览器会将存储sesssion饼干为PHPSESSID。

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

当我从新的服务器上的应用程序中删除上面的行,登录再次工作。但是,这不是一个很好的解决方案,因为其他应用程序也使用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.

和我preFER寻找奇怪的行为,而不是使用一种解决方法的原因。如果我没有修复它可能咬我别的地方。

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?

本机是一个非常赤裸裸的和基本的Ubuntu 8.04服务器,我安装的Apache2,MySQL和PHP5与资质。我也更新lokales和时区。

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.

解决方案:

我从接受的答案这code取代了线之上...

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.

推荐答案

有时的ini_set 玩起来,无法正确设置INI值,可能会下降到权限。

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

下面没有完全解决与的ini_set 的问题,如果有人知道的原因(S)为什么的ini_set 不会对某种类型的主机的工作,那么请共享!

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!

请尝试以下操作:

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

phpinfo();
?>

另外,你可以只用为session_name()来设置它,病人一直劝你不要只是运行的功能,并希望如果经常检查以声明和$在最坏的情况下p $ ppare,这就是当你的应用程序变得可靠,不error_prone。

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.

这篇关于无法更改PHP会话cookie名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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