Is it possible to detect if a user is logged into Discourse from a PHP page and get a unique ID for that user?
errrm, Discourse is not PHP
Still the question is quite normal - I suppose they’re trying to integrate the forum with a php-website, why not? The same happens with a blessed WP + Discourse support. So there should be nothing wrong with it.
I saw that but I don’t want to sign up users from PHP. I just want to detect if they are logged in and grab a unique id to give them access to other parts of my website.
I’m switching from Vanilla forums. There I could easily get a the user id from the current active session since it’s PHP based. I’m just wondering if there is some kind of solution for Discourse.
It’s possible but will require some creativity. Discourse stores an authentication token in the
_t cookie. All you have to do is get access to that cookie from the PHP site, then have PHP connect to Discourse’s PostgreSQL database, search through the
auth_token column for the cookie’s value and there you go.
The hardest part, if Discourse and your PHP site are hosted on different subdomains, is to get Discourse to set the auth cookie with a more generic path. You’ll probably have to write a small plugin and monkey-patch