• Welcome to the Chevereto user community!

    Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.

    Please keep in mind:

    • 😌 This community is user driven. Be polite with other users.
    • 👉 Is required to purchase a Chevereto license to participate in this community (doesn't apply to Pre-sales).
    • 💸 Purchase a Pro Subscription to get access to active software support and faster ticket response times.
  • Chevereto Support CLST

    Support response

    Support checklist

Check if user logged in on custom pages

teejam

Chevereto Member
Hi there -

I've looked and couldn't find the answer, but is there an easy way to check if a user is logged in, and then get at least their user id to look up the rest of their details from the DB? I've tried this on on a standalone PHP script, and it functions, but it includes page styling:

PHP:
require 'app/loader.php';
if(CHV\Login::getUser()){
    // logged in
}
else{
    // not logged in
}

Thanks :)
 
Last edited:
It is right there... CHV\Login::getUser() returns the user array.
 
It is right there... CHV\Login::getUser() returns the user array.
Thanks. Is there a way to avoid including the theme, though? Basically I'm looking for a way to manage the session in a standalone script, separate from Chevereto aside from using its session data.
 
Thanks Rodolfo. I couldn't get that to work without the theme output, so I ended up doing the following, which seems to work great:

PHP:
<?php
define('access',true);
require($_SERVER['DOCUMENT_ROOT'] . '/lib/G/G.php');
require($_SERVER['DOCUMENT_ROOT'] . '/app/lib/classes/class.settings.php');
require($_SERVER['DOCUMENT_ROOT'] . '/app/lib/classes/class.db.php');
require($_SERVER['DOCUMENT_ROOT'] . '/app/lib/classes/class.requestlog.php');
require($_SERVER['DOCUMENT_ROOT'] . '/app/lib/classes/class.user.php');
require($_SERVER['DOCUMENT_ROOT'] . '/app/lib/classes/class.login.php');

try {
    if($_SESSION['login']) {
        CHV\Login::login($_SESSION['login']['id'], $_SESSION['login']['type']);
    } else if($_COOKIE['KEEP_LOGIN']) {
        CHV\Login::loginCookie('internal');
    } else if($_COOKIE['KEEP_LOGIN_SOCIAL']) {
        CHV\Login::loginCookie('social');
    }

} catch(Exception $e) {

}

?>
 
Back
Top