# Not being logged out of auth0 at all

**URL:** <https://community.auth0.com/t/not-being-logged-out-of-auth0-at-all/56759>\
**Category:** Get Help\
**Tags:** auth0\
**Created:** [January 25, 2021, 5:31pm UTC](https://community.auth0.com/t/not-being-logged-out-of-auth0-at-all/56759 "2021-01-25T17:31:42Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![martynleeball](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/martynleeball/32/14039_2.png) [@martynleeball](https://community.auth0.com/u/martynleeball)\
**Post date:** [January 25, 2021, 5:31pm UTC](https://community.auth0.com/t/not-being-logged-out-of-auth0-at-all/56759/1 "2021-01-25T17:31:42Z")

</div>

Hey, i’m using the examples provided and simply trying to go back to the same login page after the user is logged in, so if `auth0` has got a user then we don’t hit the login method, I have more code below to run after they have logged in.

Issue i’m having is that after I login, then logout, the user still appears to be logged in, so my steps:

1. Login through `login.php`.
2. Directed back to `login.php` and the users details are displayed.
3. Logout in `logout.php`, get directed to `/`.
4. Go to `login.php` and the users details are displayed, but I should be getting sent to the login form.

`login.php`

```auto
/** @noinspection PhpUnhandledExceptionInspection*/
$auth0 = new Auth0([
	'domain' => AUTH0_DOMAIN,
	'client_id' => AUTH0_CLIENT_ID,
	'client_secret' => AUTH0_CLIENT_SECRET,
	'redirect_uri' => DMS_URL.'/login.php'
]);

if (!$user = $auth0->getUser()) {
	$auth0->login();
}
dd($user);

```

`logout.php`

```auto
/** @noinspection PhpUnhandledExceptionInspection*/
$auth0 = new Auth0([
	'domain' => AUTH0_DOMAIN,
	'client_id' => AUTH0_CLIENT_ID,
	'client_secret' => AUTH0_CLIENT_SECRET,
	'redirect_uri' => DMS_URL.'/'
]);

$auth0->logout();
$return_to = DMS_URL.'/';
$logout_url = sprintf('http://%s/v2/logout?client_id=%s&returnTo=%s', AUTH0_DOMAIN, AUTH0_CLIENT_ID, $return_to);
header('Location: ' . $logout_url);

```

**Edit:**

So, after some investigation is appears that even after hitting the `logout` page, the `$_SESSION('auth0__user')` key isn’t being cleared. Due to the documentation using `getUser()` to distinguish if a user is logged in, it doesn’t make sense for Auth0 to not clear this by default?

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [January 26, 2021, 10:16am UTC](https://community.auth0.com/t/not-being-logged-out-of-auth0-at-all/56759/2 "2021-01-26T10:16:36Z")

</div>

Hey there!

I’m not a PHP guy but maybe our PHP quickstart can be of any help here especially section about logout:

> **[Auth0 PHP SDK Quickstarts: Login](https://auth0.com/docs/quickstart/webapp/php/01-login#logout)**
>
> This guide demonstrates how to integrate Auth0 with a PHP application using the Auth0 PHP SDK.

also this one:

> **[Logout](https://auth0.com/docs/authenticate/login/logout)**
>
> Describes how logout works with Auth0.

---

<div class="post-metadata">

**Author:** ![martynleeball](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/martynleeball/32/14039_2.png) [@martynleeball](https://community.auth0.com/u/martynleeball)\
**Post date:** [January 26, 2021, 10:26am UTC](https://community.auth0.com/t/not-being-logged-out-of-auth0-at-all/56759/3 "2021-01-26T10:26:45Z")

</div>

Strangely enough, ive just tested this code again this morning and now it appears to be working as expected! Very strange, I will keep in mind them links though, thank-you.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [January 26, 2021, 11:30am UTC](https://community.auth0.com/t/not-being-logged-out-of-auth0-at-all/56759/4 "2021-01-26T11:30:27Z")

</div>

Perfect! Glad to hear that!

---

<div class="post-metadata">

**Author:** ![martynleeball](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/martynleeball/32/14039_2.png) [@martynleeball](https://community.auth0.com/u/martynleeball)\
**Post date:** [January 26, 2021, 12:14pm UTC](https://community.auth0.com/t/not-being-logged-out-of-auth0-at-all/56759/5 "2021-01-26T12:14:43Z")

</div>

Hi, turns out this issue is not resolved. I will update my question with what I have found out.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [January 26, 2021, 12:31pm UTC](https://community.auth0.com/t/not-being-logged-out-of-auth0-at-all/56759/6 "2021-01-26T12:31:39Z")

</div>

Ahh. Sure provide more details so we can try debug it further!

---

<div class="post-metadata">

**Author:** ![martynleeball](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/martynleeball/32/14039_2.png) [@martynleeball](https://community.auth0.com/u/martynleeball)\
**Post date:** [January 26, 2021, 12:37pm UTC](https://community.auth0.com/t/not-being-logged-out-of-auth0-at-all/56759/7 "2021-01-26T12:37:43Z")

</div>

Already added at the bottom of my post.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [January 26, 2021, 1:04pm UTC](https://community.auth0.com/t/not-being-logged-out-of-auth0-at-all/56759/8 "2021-01-26T13:04:26Z")

</div>

So basic logout (covered on [Auth0-PHP Basic Use](https://auth0.com/docs/libraries/auth0-php/auth0-php-basic-use)) closes the session in your application, but for customers using Single Sign-on (SSO), you also need to close the session at Auth0.

Ref:

[https://auth0.com/docs/libraries/auth0-php/using-the-authentication-api-with-auth0-php](https://auth0.com/docs/libraries/auth0-php/using-the-authentication-api-with-auth0-php)

- How to log users out of Auth0

[https://auth0.com/docs/logout/log-users-out-of-auth0](https://auth0.com/docs/logout/log-users-out-of-auth0)

---

<div class="post-metadata">

**Author:** ![martynleeball](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/martynleeball/32/14039_2.png) [@martynleeball](https://community.auth0.com/u/martynleeball)\
**Post date:** [January 27, 2021, 10:50am UTC](https://community.auth0.com/t/not-being-logged-out-of-auth0-at-all/56759/9 "2021-01-27T10:50:18Z")

</div>

I have tried this already and it doesn’t appear to work, I can still called `getUser` and return a user after I have hit the log out script.

`logout.php`

```auto
use Auth0\SDK\Auth0;

/** @noinspection PhpUnhandledExceptionInspection*/
$auth0 = new Auth0([
	'domain' => AUTH0_DOMAIN,
	'client_id' => AUTH0_CLIENT_ID,
	'client_secret' => AUTH0_CLIENT_SECRET,
	'redirect_uri' => "http://{$_SERVER['HTTP_HOST']}/dealer_interface_login.php"
]);

$auth0->logout();
$return_to = DMS_URL.'/dealer_interface_login.php';
$logout_url = sprintf('http://%s/v2/logout?client_id=%s&returnTo=%s&federated', AUTH0_DOMAIN, AUTH0_CLIENT_ID, $return_to);
header('Location: ' . $logout_url);

```

---

<div class="post-metadata">

**Author:** ![martynleeball](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/martynleeball/32/14039_2.png) [@martynleeball](https://community.auth0.com/u/martynleeball)\
**Post date:** [January 27, 2021, 12:33pm UTC](https://community.auth0.com/t/not-being-logged-out-of-auth0-at-all/56759/10 "2021-01-27T12:33:01Z")

</div>

Hi, sorry I just realized I forgot to include my session script as we use regis! So the logout script was attempting to clear a normal PHP session rather than the regis session!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [January 27, 2021, 1:24pm UTC](https://community.auth0.com/t/not-being-logged-out-of-auth0-at-all/56759/11 "2021-01-27T13:24:10Z")

</div>

Glad you have found it! Thanks for sharing with the rest of community forum!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [January 28, 2021, 4:21pm UTC](https://community.auth0.com/t/not-being-logged-out-of-auth0-at-all/56759/12 "2021-01-28T16:21:54Z")

</div>


