Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot change php session cookie name

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.

like image 333
mit Avatar asked Oct 23 '10 20:10

mit


1 Answers

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.

like image 152
RobertPitt Avatar answered Sep 17 '22 01:09

RobertPitt