Web based family history software

Question Detect Visitor

  • allan_wtf
  • Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 7 months ago #1 by allan_wtf
Detect Visitor was created by allan_wtf
Hi, I was wondering if there is an efficient way to detect whether a person has logged in or whether they are a visitor on the site.
I would like to use this as the logic portion of an IF ... THEN ... ELSE statement.

The getAttribute ('user') appears to be the routine to use and check for null, but I would appreciate knowing if you have a suggested approach.

Thanks for any guidance you can provide.

Please Log in or Create an account to join the conversation.

More
3 years 7 months ago #2 by rsbarreiro
Replied by rsbarreiro on topic Detect Visitor
Explain better what you intend to do ...
Do you want to create a module? just want to know if the user is logged in or need to know the access level?

assuming you are creating a module ...
at the beginning of your file you should have the line:
Code:
use Fisharebest\webtrees\Auth;

take a look at the "Auth.php" file inside the "app" folder and you will see several functions that you can use to know the user's id, type of access, etc ...

* translated by google (originally in Brazilian Portuguese)

Please Log in or Create an account to join the conversation.

More
3 years 7 months ago #3 by fisharebest
Replied by fisharebest on topic Detect Visitor
> The getAttribute ('user') appears to be the routine to use and check for null

This is the recommended solution.

> take a look at the "Auth.php" file

You can also use the global/static Auth class.

if (Auth::check()) {
// Logged in
} else {
// Visitor
}

However, global-functions / static-classes are generally regarded as a bad design, and are being slowly phased out.

Greg Roach - greg@subaqua.co.uk - @fisharebest@phpc.social - fisharebest.webtrees.net

Please Log in or Create an account to join the conversation.

  • allan_wtf
  • Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 7 months ago #4 by allan_wtf
Replied by allan_wtf on topic Detect Visitor
I will look at the Auth.php file, that should do it.
As an answer to rsbarreiro - nothing complicated - logged in members get access to links to additional content, which a visitor does not see. No access level required. This is part of a custom module.

Thanks for the response

Please Log in or Create an account to join the conversation.

Powered by Kunena Forum
}