I’ve written some educational web apps (HTML, js) for my kids. I’ve gotten to the point where I need to start tracking their progress individually, so the apps can focus more on what the individual still needs to learn, and spend less time repeating what they already know well.
To do that, I’ve created a Drupal site, with logins for each of the kids. Once they log in thru Drupal, I would like to have my app call some php pages (which I will write) that access Drupal’s authentication states.
So my question is, if I’m writing php pages that query or update a database, how can these pages first ascertain whether the user is logged in to Drupal on that site, and if so, get the name of the currently authenticated user?
Many thanks for any pointers.
Start your pages with this code (taken from Drupal’s index.php)
You may need to adjust the paths if your scripts aren’t in the same folder as Drupal’s index.php.
Then you have full access to the Drupal API in your script, and the user’s session will be loaded. You’ll need to bootstrap Drupal with this code before the suggestion above will work. From there, you can do
Now you can do things like:
In the long run you really would get a lot of benefits from building this as a Drupal module.