Search code examples
sessioniframecookiesdrupal-7moodle

Drupal in Moodle sharing session


I have a Moodle site, in one of the Moodle pages I have an iFrame which contains a Drupal application. I want the Drupal application to see whether the user is logged in on Moodle, and if so show extra content.

However, I cannot access the session data from Moodle (especially information on the User) to in Drupal.

I tried two things:

  • If the iframe was a normal PHP page, I'd pass session_start(); on the top of the page in order for the session to persists, but I have no idea HOW to do that in Drupal.
  • And since they are on the same server, I tried accessing the config.php file in Moodle from a plain PHP file in the Drupal directory, and, as expect, I was able to get the variable. But as soon as I do this inside the Drupal application, a clash in function name between Moodle and Drupal threw an error.
  • The other option is to add a plugin in Moodle which sets a cookie on user login, a cookie that Drupal can get. But I'm really against this option since anyone can set a cookie and it persists. (There's no guarantee the user will click log-out)

I've never used/touched Moodle and Drupal until today. Can anyone help me figure out how to check whether a user is logged in on Moodle, from an iframe running a Drupal application?


Solution

  • A quick google gives the following moodle plugin that may be useful: https://moodle.org/mod/forum/discuss.php?d=208285

    Looks like it allows single sign-on between the two, I've never used moodle before, but this may be a step in the right direction.