brfcs Posted July 31, 2022 Posted July 31, 2022 Our site is split into a few sections, the main ones being the forum and the "editorial" style content on the front page. They both sit on the same domain so share cookies etc, and I want to be able to make use of the fact that a viewer is logged in so we can customise content for them, and have some interactive content where we use their ID or some token as a unique identifier. If a user hits the forum first, they have a cookie set `ips4_member_id` but the TTL on this cookie is a couple of hours ago so it doesn't persist even as long as the session. Is there a way to get the info I need? Just a unique identifier for the logged in user.
Nathan Explosion Posted July 31, 2022 Posted July 31, 2022 (edited) <?php require_once 'test/ips_47_test/init.php'; \IPS\Session\Front::i(); $member = \IPS\Member::loggedIn(); if($member->member_id){ echo "Logged in"; } else { echo "not logged in"; } You'll need to modify the 'require_once' path to match up to the location where the init.php for IPS is located based on the location of your script file (my php file is in root, the IPS install is in test/ips_47_test/) Edited July 31, 2022 by Nathan Explosion SeNioR- 1
brfcs Posted July 31, 2022 Author Posted July 31, 2022 Unfortunately the magazine section of the site is a seperate codebase, controlled by a CRM and written in VueJS/NutxJS, so I'd have to hit some kind of API endpoint to get the required info.
Solution Nathan Explosion Posted July 31, 2022 Solution Posted July 31, 2022 In that case you'll likely have to use the cookie you mentioned (which expires after 3 months) That gives you the user's ID, and you could then use the REST API to get more information about that user. SeNioR- and brfcs 1 1
brfcs Posted August 10, 2022 Author Posted August 10, 2022 The reason I was asking about the cookie was some of my users were seeing really odd behaviour (and I saw it myself too). If I clicked a link to a specific page from an email or Discord, that tried to access the value of the cookie it would fail, and when I inspected the page, the cookie wasn't present, none of the IPS ones were. However, type the same link in and it worked fine. It wasn't a case of the cookie being set by the visit from Discord because I could click the link again and see the same thing. I had a hunch it was down to the way the cookies were being loaded, I didn't know if the browser would load any stored cookies before making the initial call. It should, but it was the only scenario I could think of where they wouldn't be available. I had a bit of a shuffle round with where in the lifecycle the cookie is accessed by my app (VueJS & NuxtJS based) and the issue seems to have gone away, but because I don't know the cause of the issue I'm not 100% sure it's properly fixed.
Recommended Posts