formtools / api

The Form Tools API.
https://docs.formtools.org/api/
15 stars 16 forks source link

Check if logged in #15

Closed sf23103 closed 5 years ago

sf23103 commented 5 years ago

I am looking to add code to a non FT page that determines if a user is logged in. It most likely won't matter much WHICH user is logged in, just that a valid user is logged in. The other option was to paste my code into one of the pages on the page module but that doesn't really accept html/php combo very well.

I see there is an API function that allows someone to log in programmatically, but is there a way to check to see if someone is logged in already?

EDIT: I played around with it this morning, and tried a few functions such as ft_get_account_info(). What I ended up with is determining if ['is_logged_in'] is set to true within the session. The problem I am having with that is even when I log out of FT, it continues to say I'm logged in, and in another browser it just always says I'm logged out. Am I on the right track here?

require("/path/to/ft/global/session_start.php");

if ($_SESSION['ft']['account']['is_logged_in'] == true) {
echo 'logged in!'; }

else { echo "Not logged in!!"; }

EDIT 2:

My issue seemed to be with FT being https and my script running without https. Sessions seem to be tied pretty tightly to the domain, i.e. with and without https, and www subdomain. All works well when I've got it all the same. If anyone has any suggestions as to any better methods, I'm open to it!

sf23103 commented 5 years ago

This was solved by including global/library.php and then:

FormTools\Core::init();

then check sessions..

Thanks Ben!