Hello all! I'm working on a site that has multiple components - a Xenforo server (e.g. forums.xyz.com), a Laravel API server (api.xyz.com) and a WordPress site (xyz.com). These are all running on the same physical server, but some are using their own web servers. I don't have much experience with Xenforo, which doesn't help matters. Here's the gist:
We intend on using XenForo (forums.xyz.com) to authenticate the user. XenForo's config is set up so that the cookie domains are for .xyz.com.
Most of the code that's accessing the forum user data is in JavaScript on the WordPress site, typically calling the Laravel API server via AJAX.
The issue I'm running into now is how to get the user id from Xenforo (in any way) to use it with the Laravel API call (e.g. "get all orders from user 12345".) Attempting to use XenForo code in the Laravel API to get the userid does not work - the code cannot see the session cookie apparently. If I hit the API directly, it works, but not via AJAX (I'm assuming the session cookie can't be read.) I also tried using XenForo code as a PHP Anywhere "snippet" on WP, but the same issue - the code works directly in the browser, but it's not (for whatever reason) getting a valid session/user and therefore can't get the userid.
If the user has clicked "remember me," I can parse the xf_session value for the id, but that's not a universal solution.
An example of the code:
If anybody had any insights, I'd be very grateful! Thanks!
We intend on using XenForo (forums.xyz.com) to authenticate the user. XenForo's config is set up so that the cookie domains are for .xyz.com.
Most of the code that's accessing the forum user data is in JavaScript on the WordPress site, typically calling the Laravel API server via AJAX.
The issue I'm running into now is how to get the user id from Xenforo (in any way) to use it with the Laravel API call (e.g. "get all orders from user 12345".) Attempting to use XenForo code in the Laravel API to get the userid does not work - the code cannot see the session cookie apparently. If I hit the API directly, it works, but not via AJAX (I'm assuming the session cookie can't be read.) I also tried using XenForo code as a PHP Anywhere "snippet" on WP, but the same issue - the code works directly in the browser, but it's not (for whatever reason) getting a valid session/user and therefore can't get the userid.
If the user has clicked "remember me," I can parse the xf_session value for the id, but that's not a universal solution.
An example of the code:
Code:
require('/var/www/forum/src/XF.php');
\XF::start('/xyz');
$app = \XF::setupApp('XF\Pub\App');
$s = $app->session();
$uid = $s->get('userId');
If anybody had any insights, I'd be very grateful! Thanks!
Last edited: