Session validation on custom/standalone php file


I have a custom/stand alone PHP page/file in the root of the NextCloud installation serving some content.
This custom PHP file is published in NextCloud with the “External Sites” NextCloud app to NextCloud users.
I like to add some code to this PHP file which validates if there is a valid NextCloud user login session.
(if there is a valid NextCloud login session show the content, if there is not a valid NextCloud session redirect to the login page)

Can anybody help me in the right direction how to do this, maybe provide me with some “Hello World” example code

Thanks in advance