Check if user logged in on custom pages

teejam

Network license
License owner
Joined
Jun 15, 2018
Messages
28
Likes
11
Points
53
#1
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:

teejam

Network license
License owner
Joined
Jun 15, 2018
Messages
28
Likes
11
Points
53
#3
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.
 

teejam

Network license
License owner
Joined
Jun 15, 2018
Messages
28
Likes
11
Points
53
#5
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) {

}

?>