PHP website with Discourse


#1

Is it possible to detect if a user is logged into Discourse from a PHP page and get a unique ID for that user?


(Mittineague) #2

errrm, Discourse is not PHP


(Anton) #3

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.


(cpradio) #4

Read


#5

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.


(Jens Maier) #6

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 users table’s 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 Auth::DefaultCurrentUserProvider#log_on_user.