How to get user cookie or user name /user id in external PHP file

PHP:
<?php

$dir = __DIR__;
require ($dir . '/src/XF.php');

XF::start($dir);
$app = XF::setupApp('XF\Pub\App');
$app->start();

Missed a line. That should work.
Hey Chris, one more question - is there a reason why this doesn't work above the forum directory? For example, if I include it in a file inside the forum (this session file is stored in the forum directory/forum/), everything works just fine. But if I include it in a file located in my root directory, it returns a zero for the user_id so I'm assuming maybe another line needs to be added to pick up the session...?
 
Hey Chris, one more question - is there a reason why this doesn't work above the forum directory? For example, if I include it in a file inside the forum (this session file is stored in the forum directory/forum/), everything works just fine. But if I include it in a file located in my root directory, it returns a zero for the user_id so I'm assuming maybe another line needs to be added to pick up the session...?
Disregard this - this was an issue only on the local installation. The mirrored version online works exactly as expected.
 
PHP:
<?php

$dir = __DIR__;
require ($dir . '/src/XF.php');

XF::start($dir);
$app = XF::setupApp('XF\Pub\App');
$app->start();

Missed a line. That should work.
Chris

When someone is logged in like this in an external page. How do they show up in the Members Online location? And can we set this to a custom location easily?
 
When someone is logged in like this in an external page. How do they show up in the Members Online location? And can we set this to a custom location easily?
Unless you're invoking the dispatcher and a public controller, session activity (which drives members online status) is not updated. You would have to call \XF\Repository\SessionActivity::updateSessionActivity manually. You can see how it's done in \XF\Pub\Controller\AbstractController::updateSessionActivity.

The currently viewed page is derived from routing information (a controller name and action, among other things), so it's not quite as simple as passing in a phrase and URL. If there's not an existing controller for what you want to display there, you'd have to create one (even if your custom page isn't really "routing" to it) and implement getActivityDetails.
 
  • Like
Reactions: arn
Top Bottom