Detecting if on frontend / backend

Hello everyone,
is there a quick way to detect if the user’s working in the backend / frontend? I could check if the current user is logged in, but out of curiosity, is there another way to do it?

thx

You could check on the url if the panel segment is in it?

how that? and thanks for the quick reply!
and it seems to me that putting header() inside if statements generally doesn’t work …

Try with the URL helper in Kirby’s toolkit: e.g. url::current() or url::path().

By the way, checking if the user is logged in doesn’t tell you if the user is actually active in the Panel or not. It just means that the user is logged in.

What is your use case?

Since my CSP header rules break some of the backend magic, I want to apply them frontend-only!

The easiest way to detect the Panel in Kirby 2 is the following check:

if (class_exists('Kirby\Panel')) {
  ...
}
4 Likes