# Know if a user is authenticated on panel in the public website

**URL:** <https://forum.getkirby.com/t/know-if-a-user-is-authenticated-on-panel-in-the-public-website/15920>\
**Category:** Questions\
**Tags:** v2\
**Created:** [October 11, 2019, 6:15am UTC](https://forum.getkirby.com/t/know-if-a-user-is-authenticated-on-panel-in-the-public-website/15920 "2019-10-11T06:15:35Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![roberto.sanval](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/roberto.sanval/32/6391_2.png) [@roberto.sanval](https://forum.getkirby.com/u/roberto.sanval)\
**Post date:** [October 11, 2019, 6:15am UTC](https://forum.getkirby.com/t/know-if-a-user-is-authenticated-on-panel-in-the-public-website/15920/1 "2019-10-11T06:15:35Z")

</div>

Hello,

I’d like to know how can I know in my public website if a user is logged in in panel.

Thanks

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [October 11, 2019, 7:19am UTC](https://forum.getkirby.com/t/know-if-a-user-is-authenticated-on-panel-in-the-public-website/15920/2 "2019-10-11T07:19:07Z")

</div>

```auto
<?php if ($user = $site->user()) {
  echo "The user is logged in";
}
?>

```

If you need to check for a specific user or role, you can do that as well.

[http://k2.getkirby.com/docs/cheatsheet#user](http://k2.getkirby.com/docs/cheatsheet#user)

---

<div class="post-metadata">

**Author:** ![roberto.sanval](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/roberto.sanval/32/6391_2.png) [@roberto.sanval](https://forum.getkirby.com/u/roberto.sanval)\
**Post date:** [October 11, 2019, 7:36am UTC](https://forum.getkirby.com/t/know-if-a-user-is-authenticated-on-panel-in-the-public-website/15920/3 "2019-10-11T07:36:10Z")

</div>

> [@texnixe](#):
>
> \<?php if ($user = $site-\>user()) { echo "The user is logged in"; }

That’s what I was trying but I always get NULL, nevertheless if I use the same code in panel controllers everything works fine.

What could be happening?

Thanks

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [October 11, 2019, 7:37am UTC](https://forum.getkirby.com/t/know-if-a-user-is-authenticated-on-panel-in-the-public-website/15920/4 "2019-10-11T07:37:39Z")

</div>

Where are you using this code? In a template, a plugin?

---

<div class="post-metadata">

**Author:** ![roberto.sanval](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/roberto.sanval/32/6391_2.png) [@roberto.sanval](https://forum.getkirby.com/u/roberto.sanval)\
**Post date:** [October 11, 2019, 7:51am UTC](https://forum.getkirby.com/t/know-if-a-user-is-authenticated-on-panel-in-the-public-website/15920/5 "2019-10-11T07:51:32Z")

</div>

In a controller on the public site

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [October 11, 2019, 8:03am UTC](https://forum.getkirby.com/t/know-if-a-user-is-authenticated-on-panel-in-the-public-website/15920/6 "2019-10-11T08:03:14Z")

</div>

Hm, that’s strange; could you please post the complete code?

What are you trying to achieve, anyway?

---

<div class="post-metadata">

**Author:** ![roberto.sanval](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/roberto.sanval/32/6391_2.png) [@roberto.sanval](https://forum.getkirby.com/u/roberto.sanval)\
**Post date:** [October 11, 2019, 8:13am UTC](https://forum.getkirby.com/t/know-if-a-user-is-authenticated-on-panel-in-the-public-website/15920/7 "2019-10-11T08:13:57Z")

</div>

In home.php:

```
<?php
return function($site, $pages, $page) {

    if ($user = $site->user()) {
        echo "The user is logged in";
    }
    else {
        echo "No user";
    }
```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [October 11, 2019, 8:21am UTC](https://forum.getkirby.com/t/know-if-a-user-is-authenticated-on-panel-in-the-public-website/15920/8 "2019-10-11T08:21:21Z")

</div>

And you always get “no user”, no matter if you are logged in or not? That’s weird.

---

<div class="post-metadata">

**Author:** ![roberto.sanval](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/roberto.sanval/32/6391_2.png) [@roberto.sanval](https://forum.getkirby.com/u/roberto.sanval)\
**Post date:** [October 11, 2019, 8:22am UTC](https://forum.getkirby.com/t/know-if-a-user-is-authenticated-on-panel-in-the-public-website/15920/9 "2019-10-11T08:22:53Z")

</div>

Exactly! I’ve spent hours trying to understand this. Any ideas?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [October 11, 2019, 8:24am UTC](https://forum.getkirby.com/t/know-if-a-user-is-authenticated-on-panel-in-the-public-website/15920/10 "2019-10-11T08:24:36Z")

</div>

So lets say you log into the Panel, open the home page in the Panel and then click on the preview link, you still see “No user” and if you go back into the Panel you are still logged in?

---

<div class="post-metadata">

**Author:** ![roberto.sanval](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/roberto.sanval/32/6391_2.png) [@roberto.sanval](https://forum.getkirby.com/u/roberto.sanval)\
**Post date:** [October 11, 2019, 8:26am UTC](https://forum.getkirby.com/t/know-if-a-user-is-authenticated-on-panel-in-the-public-website/15920/11 "2019-10-11T08:26:46Z")

</div>

Yes, but I see that the preview link is simple link, nothing special on it, only a target="\_blank", that’s correct?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [October 11, 2019, 8:28am UTC](https://forum.getkirby.com/t/know-if-a-user-is-authenticated-on-panel-in-the-public-website/15920/12 "2019-10-11T08:28:45Z")

</div>

Yes, the preview link is just a link.

And we are talking about Kirby 2 here, not Kirby 3?

---

<div class="post-metadata">

**Author:** ![roberto.sanval](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/roberto.sanval/32/6391_2.png) [@roberto.sanval](https://forum.getkirby.com/u/roberto.sanval)\
**Post date:** [October 11, 2019, 8:29am UTC](https://forum.getkirby.com/t/know-if-a-user-is-authenticated-on-panel-in-the-public-website/15920/13 "2019-10-11T08:29:55Z")

</div>

> [@texnixe](#):
>
> e are talking about Kirby 2 here, not

Yes:

`static public $version = '2.5.10';`

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [October 11, 2019, 8:30am UTC](https://forum.getkirby.com/t/know-if-a-user-is-authenticated-on-panel-in-the-public-website/15920/14 "2019-10-11T08:30:59Z")

</div>

Hm, I know that the code works. Could you update to 2.5.12 (the latest version)?

---

<div class="post-metadata">

**Author:** ![roberto.sanval](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/roberto.sanval/32/6391_2.png) [@roberto.sanval](https://forum.getkirby.com/u/roberto.sanval)\
**Post date:** [October 11, 2019, 8:33am UTC](https://forum.getkirby.com/t/know-if-a-user-is-authenticated-on-panel-in-the-public-website/15920/15 "2019-10-11T08:33:09Z")

</div>

I don’t know because this is not my project and I don’t know if I’ll break something 😕

I’ll try to do it making a full backup.

There’s any update guide?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [October 11, 2019, 8:34am UTC](https://forum.getkirby.com/t/know-if-a-user-is-authenticated-on-panel-in-the-public-website/15920/16 "2019-10-11T08:34:55Z")

</div>

Updating means removing the `kirby` and `panel` folders and replacing them with the new ones.

---

<div class="post-metadata">

**Author:** ![roberto.sanval](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/roberto.sanval/32/6391_2.png) [@roberto.sanval](https://forum.getkirby.com/u/roberto.sanval)\
**Post date:** [October 11, 2019, 8:35am UTC](https://forum.getkirby.com/t/know-if-a-user-is-authenticated-on-panel-in-the-public-website/15920/17 "2019-10-11T08:35:21Z")

</div>

Thanks, I’ll try it and reply here the result

---

<div class="post-metadata">

**Author:** ![roberto.sanval](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/roberto.sanval/32/6391_2.png) [@roberto.sanval](https://forum.getkirby.com/u/roberto.sanval)\
**Post date:** [October 11, 2019, 8:40am UTC](https://forum.getkirby.com/t/know-if-a-user-is-authenticated-on-panel-in-the-public-website/15920/18 "2019-10-11T08:40:19Z")

</div>

Exact same result 😭

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [October 11, 2019, 8:41am UTC](https://forum.getkirby.com/t/know-if-a-user-is-authenticated-on-panel-in-the-public-website/15920/19 "2019-10-11T08:41:28Z")

</div>

Hm, are you testing locally or is the project online somewhere?

---

<div class="post-metadata">

**Author:** ![roberto.sanval](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/roberto.sanval/32/6391_2.png) [@roberto.sanval](https://forum.getkirby.com/u/roberto.sanval)\
**Post date:** [October 11, 2019, 8:42am UTC](https://forum.getkirby.com/t/know-if-a-user-is-authenticated-on-panel-in-the-public-website/15920/20 "2019-10-11T08:42:09Z")

</div>

I’m trying locally but the website is published and working

[Next page](https://forum.getkirby.com/t/know-if-a-user-is-authenticated-on-panel-in-the-public-website/15920.md?page=2)
