0

Drupal 7.

I have a site with Single Sign On (SSO) implemented. The implementation of the features is complete and the site is running perfectly.

Now, I have a requirement where I am supposed to check whether the session of the central server (on root of the domain and not using Drupal) is alive. I can do this by checking the availability of the session cookie on the root domain. And if the session is not active the user is logged out of Drupal.

I tried implementing it inside hook_init() but it only works for non-cached pages, whereas I want my code to be triggered on every page.

I also had a look at hook_boot() which runs even on cached pages. But, it is called while Drupal is still in bootstrap mode; even before themes and modules are loaded into memory. Which would mean that I would not be able to check the status of the user (whether the user is logged in?), because the user module and the included file session.inc would not be present in the memory while the execution of this hook.

So my question is which function (or hook) should I use which would execute on all pages(cached and non-cached) and which would give me access to common user properties (e.g. global $user object, user_is_logged_in() function etc)?

  • How are you caching pages for logged in users? Naively, they are only cached for anonymous users, at least via core drupal anyway. – Jimajamma Feb 5 '13 at 14:27
0

(I'm assuming Drupal 6)

Looking at bootstrap.inc, hook_boot is called on all pages, as long as agressive caching hasn't been turned on.

At this point the global $user variable should already exist (page_get_cache, which is called before hook_boot, makes use of it for example). module.inc has also been included, so you can use the functions included in that file to check for module existance and load them if necessary.

So, hook_boot looks like a good choice.

  • Sorry, I should have mentioned I'm using Drupal 7. However, your suggestion makes sense, and I would look at drupal_page_get_cache which is the D7 alternative for page_get_cache. I appreciate your prompt response. – AjitS Feb 5 '13 at 7:12
  • 1
    With drupal 7, as long as page_cache_invoke_hooks is true (equivalent of agressive caching), boot_hook should get called, and the global $user varaible is already set at that point, so it should work the same. – penten Feb 5 '13 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.