# CakePHP 4.5 Session was already started on logout

**URL:** <https://discourse.cakephp.org/t/cakephp-4-5-session-was-already-started-on-logout/12035>\
**Category:** Need Help\
**Tags:** help\
**Created:** [May 23, 2024, 8:59am UTC](https://discourse.cakephp.org/t/cakephp-4-5-session-was-already-started-on-logout/12035 "2024-05-23T08:59:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![zegert](https://avatars.discourse-cdn.com/v4/letter/z/bbce88/32.png) [@zegert](https://discourse.cakephp.org/u/zegert)\
**Post date:** [May 23, 2024, 8:59am UTC](https://discourse.cakephp.org/t/cakephp-4-5-session-was-already-started-on-logout/12035/1 "2024-05-23T08:59:54Z")

</div>

I’m trying to upgrade to PHP 4.5 and everything is going flawless except logging out.

CakePHP 4.5.5

CakePHP/Authorisation 2.10.2

When logging out in:

```php
APP/Controller/UsersController.php

public function logout()
{
    $result = $this->Authentication->getResult();

    if ($result->isValid()) {
       $this->Authentication->logout();
       return $this->redirect(['controller' => 'Users', 'action' => 'login']);
    }
}

```

I’m going to:

```php
ROOT/vendor/cakephp/authentication/src/Controller/Component/AuthenticationComponent.php at line311 in Authentication\AuthenticationService->clearIdentity

$result = $this->getAuthenticationService()->clearIdentity(
     $controller->getRequest(),
     $controller->getResponse()
);

```

And further:

```php
ROOT/vendor/cakephp/authentication/src/AuthenticationService.php at line224 in Authentication\Authenticator\SessionAuthenticator->clearIdentity

$result = $authenticator->clearIdentity($request, $response);

```

And it wants to renew the session:

```php
ROOT/vendor/cakephp/authentication/src/Authenticator/SessionAuthenticator.php at line115 in Cake\Http\Session->renew

$sessionKey = $this->getConfig('sessionKey');
/** @var \Cake\Http\Session $session */
$session = $request->getAttribute('session');
$session->delete($sessionKey);
$session->renew();

```

It starts the new session

```php
CORE/src/Http/Session.php at line649 in Cake\Http\Session->start

if (!$this->_hasSession() || $this->_isCLI) {
	return;
}
	
$this->start();
$params = session_get_cookie_params();

```

And crashes here:

```php
CORE/src/Http/Session.php at line 352

if (session_status() === \PHP_SESSION_ACTIVE) {
	throw new RuntimeException('Session was already started');
}

```

This seems strange to me, code worked fine for CakePHP 4.3.
