You can regenerate your session id with the ZF2 SessionManager
:
$manager = new Zend\Session\SessionManager;
$manager->regenerateId();
However, your error is likely not caused by this function, but because of something else. Session management (either session_start()
or regenerating session ids) is only possible when you haven't used echo
or something similar before that piece of code:
As an example, this will fail:
<?php
echo 'Hello';
session_start();
On the other hand, this will just work:
<?php
session_start();
echo 'Hello';
You have to be very careful with opening and closing php tags. If you have any closing php tag in your classes, remove them. If there is blank line after this, it's interpreted as text which is returned in the response and this causing troubles with sessions. This will fail as well:
<?php
// Do some work
?>
<!-- blank line -->
<?php
session_start();
?>
So: check all your code for echo
, print
etcetera. Also, check for any closing php tag in your source code. If all above things won't help you, post the piece of code where you are regenerating your session id, that might give some more insights.