1

I have an external php app that sits in a subdirectory in the public folder on the same server (and domain) as craft. I am trying to use bootstrap.php to check the logged in status of the current user. Is this possible?

It is currently working for me by checking that the user is logged in (it does return false while not logged in) - but after the user logs out of craft the bootstrap.php continues to return true that the user is logged in.

$craft = require '../../craft/app/bootstrap.php';
if ($craft->userSession->isAdmin() && $craft->userSession->isLoggedIn() ){
 // this returns after a log in, but continues to be true after a log out. It does not return true initially before using both craft and this script.
}

Hopefully that makes sense, any ideas?

I also could not get the onLogout or onBeforeLogout to execute. I see it is in the class reference, but not listed in the event documentation:

public function init()
{

    craft()->on('usersession.onLogout', function(Event $event) {
        echo "THIS DOES NOT EXECUTE";
        die();
    });

    parent::init();
}

Is it possible the log out event is not triggering?

2
  • Where does that init() method live?
    – Brad Bell
    Oct 20 '14 at 22:27
  • In the main class of the plugin. Oct 20 '14 at 23:49
1

I just tested this and it works as you'd expect it to work for me locally:

<?php

$craft = require '/path/to/craft/app/bootstrap.php';

if ($craft->userSession->isAdmin())
{
    echo 'I am an admin.';
}
else
{
    echo 'I am not an admin.';
}

if ($craft->userSession->isLoggedIn())
{
    echo 'I am logged in.';
}
else
{
    echo 'I am not logged in.';
}
4
  • I will use your script stand alone. Will report back shortly. Oct 20 '14 at 23:50
  • Ever figure this out, @LukeHolder?
    – Brad Bell
    Oct 31 '14 at 1:23
  • will jump in right now and take a look at it again. Oct 31 '14 at 3:51
  • works for me, think it was a bug with my session code for the app that was using the bootstrap. Oct 31 '14 at 5:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.