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

<pre><code>&lt;?php

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

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

if ($craft-&gt;userSession-&gt;isLoggedIn())
{
    echo 'I am logged in.';
}
else
{
    echo 'I am not logged in.';
}
</code></pre>

CC BY-SA 3.0
2014-10-20T23:50:41.453Z
I will use your script stand alone. Will report back shortly.
Luke Holder
CC BY-SA 3.0
2014-10-31T01:23:51.740Z
Ever figure this out, @LukeHolder?
Brad Bell
CC BY-SA 3.0
2014-10-31T03:51:22.710Z
will jump in right now and take a look at it again.
Luke Holder
CC BY-SA 3.0
2014-10-31T05:50:22.653Z
works for me, think it was a bug with my session code for the app that was using the bootstrap.
Luke Holder
CC BY-SA 3.0
2014-10-20T22:26:50.763Z
2014-10-20T22:26:50.763Z
Brad Bell
<p>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?</p>

<p>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.</p>

<pre><code>$craft = require '../../craft/app/bootstrap.php';
if ($craft-&gt;userSession-&gt;isAdmin() &amp;&amp; $craft-&gt;userSession-&gt;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.
}
</code></pre>

<p>Hopefully that makes sense, any ideas?</p>

<p>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:</p>

<pre><code>public function init()
{

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

    parent::init();
}
</code></pre>

<p>Is it possible the log out event is not triggering?</p>

CC BY-SA 3.0
2014-10-20T22:27:11.523Z
Where does that `init()` method live?
Brad Bell
CC BY-SA 3.0
2014-10-20T23:49:47.573Z
In the main class of the plugin.
Luke Holder
<plugin-development><session>
log out being shared with bootstrap.php
# log out being shared with bootstrap.php

(Asked by: username_0 on 2014-10-20)

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?

**Tags:** plugin-development, session

> **Comments:**
> **username_1**: Where does that `init()` method live?  
> **username_0**: In the main class of the plugin.  

---

## 1 answers

### Answer by username_1 on 2014-10-20. Score: 1

I just tested this and it works as you'd expect it to work for me locally:
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.';
}

> **Comments:**
> **username_0**: I will use your script stand alone. Will report back shortly.  
> **username_1**: Ever figure this out, @LukeHolder?  
> **username_0**: will jump in right now and take a look at it again.  
> **username_0**: works for me, think it was a bug with my session code for the app that was using the bootstrap.  

---

