XF 2.0 How to create session on behalf of another IP address

SamJakob

Active member
I have an external PHP file that is used in conjunction with another application:

I am requiring XenForo's XF.php at the top of the file (and instantiating an App instance - not sure if it's necessary):
PHP:
require("../../../XF.php"); // Directory is /var/www/xenforo/src/

XF::start("../../../../"); // Directory is /var/www/xenforo/
$app = XF::setupApp('XF\Pub\App');

I want to authenticate a user with another IP address automatically (the application runs on a server and uses a secure method of communication with the PHP file.)
I've got to the point of looking up the user to retrieve their user ID and username - and then using a finder to create a User object.

PHP:
$finder = \XF::finder('XF:User');
$user = $finder->where('username', $username)->fetchOne();

Now, I want to switch the session user as you would below;
PHP:
$app->session->changeUser($user);
\XF::setVisitor($user);

...but I want this session to be for an IP address other than the one requesting the PHP file (as that's just the application running on the server.)
Is there a way for me to create a session for that other IP address or do I apply the information to this session and somehow change the IP address of this session?
 
Okay, I've found a solution.
I simply pushed the information I needed to a database table, then I added a code event listener for app pub start begin and changed the session user there.
 
Okay, I've found a solution.
I simply pushed the information I needed to a database table, then I added a code event listener for app pub start begin and changed the session user there.

You weren't able to create a session extending the login controller?
 
Ahh okay, fair enough man! I figured this out a while ago was gonna help out if you needed it.
If you've got some pointers I'd be happy to note them down - I think that'd be useful in the future and for anyone referencing this thread in the future.
 
Top Bottom