2

I have a drupal web site that lives on the same domain as another non-drupal website.For instance, The site is a.example.com. When my users logs in example.com a certain authentication cookie is set. However, when the user hit a.example.com, the user gets a cache hit. I know that hook_boot is invoked on all pages, however, how do I tell Drupal to bypass cache? Should I set a certain cookie?
I would like to now what is the proper way of doing something like this.

1

I would suggest looked at the Single Sign options of Drupal or implement some code that logs you into Drupal when they login to the non-Drupal site.

EDIT: first, boostrap Drupal and then run this function:

function drupal_user_login($username, $password)
{
    $uid = user_authenticate($username, $password);
    if($uid)
    {
        $form_state = array();
        $form_state['uid'] = $uid;
        user_login_submit(array(), $form_state);

        return true;
    }
    else
    {
        return false;
    }
}
  • Thank you. This can be very helpful. The thing is I have only seen sso modules assumes a user is logging in through drupal. My use case requires if the user is logged in on say facebook for example , then drupal automatically loggs you in. This is only possible the sites are on shared domain and have access to some auth cookie. – awm Oct 9 '13 at 16:03
  • This may help you with your coding: drupal.stackexchange.com/questions/5825/… – Scott Joudry Oct 9 '13 at 16:10
0

I did some research and came up with one implementation on bypassing cache. The idea is you cannot bypass the page cache if no hooks are invoked at all when the page is in cache. Only hook_boot and hook_exit are invoked and only if page_cache_invoke_hooks is set to TRUE. The default value of this hook is TRUE but many caching module, such as Varnish Module, requires this page_cache_invoke_hooks to be set to FALSE (I don't know why). In the case when page_cache_invoke_hooks is set to TRUE I was able to dynamically toggel cache on and of in the following manner:

 /**
 * Implements hook_boot().
 */
function somemodule_boot() {

  if (need_tobyapss_cache()) {
    // Set the proper cache header.
    header('X-Drupal-Cache: MISS');

    // Do not cache this page. Otherwise this page could be cached in a logged

    drupal_page_is_cacheable(FALSE);

    // Continue the bootstrap process.
    drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL, FALSE);

    // Execute the page callback and exit.
    menu_execute_active_handler();

    exit;
  }
}

Again, this relies on page_cache_invoke_hooks being set to TRUE. iF it is set to FALSE drupal will not invoke hook_boot or hook_exit.

Also, there is an ongoing core issue about allowing developer to dynamically toggle cache on/off. https://drupal.org/node/322104

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.