Conditional Caching for anonymous users

Events happening in the community are now at Drupal community events on www.drupal.org.
shadysamir's picture

We are building a website where anonymous users need to be validated using their IP address and hence providing them with different content and page builds based on their identity detected by their current IP. We have full control of the IP allocation and are able to determine users based on that. We wish that users do not need to register an account with the website to access this content. Boost is being used for caching.

We were not able to assign a non-anonymous role to users coming from a certain IP pool. And dealing with anonymous users leads to either their version of the site to be cached for all users even those coming from outside the pool, or those users getting the anonymous cached pages.

There could be many solutions for this problem that we are not aware of, ideas are welcomed, but the one we were thinking of was to do conditional caching, that is to do a check on the first request from a certain IP, if it is within the pool of IPs we offer a non-cahced, php processed copy of the site, otherwise just serve the boost cached version. Where to begin?

Comments

We were not able to assign a

dalin's picture

We were not able to assign a non-anonymous role to users coming from a certain IP pool.

Why not? This seems like the way to do it. Plus you'd need to add rules to .htaccess to bypass Boost for these IPs.

--


Dave Hansen-Lange
Director of Technical Strategy, Advomatic.com
Pronouns: he/him/his

Use a cookie

mikeytown2's picture

Do a ajax callback to check if the ip address is part of the range. Javascript can not access the clients ip address AFAIK; thus the need for a ajax call. If user is part of the ip range then use javascript to reload the page with caching turned off (set drupal_uid cookie to something other then 0 or -1).

I did something similar but with the memcache module and using geoip lookup to assign a user to an organic group; even if they are anonymous via hook_exit.
http://drupal.org/node/952620

Here is the javascript code I use to set a cookie

/**
* @param nid
*   Sets a cookie on the users computer to save the group number they are apart of
*/
function og_oven_set(nid) {
  var myDate = new Date();
  myDate.setTime(myDate.getTime() + (Drupal.settings.og_oven.expire_time*1000));
  document.cookie = Drupal.settings.og_oven.cookie_name + '=' + nid + ';'
    + ' expires=' + myDate.toGMTString() + ';'
    + ' path=/' + ';'
    + ' domain=.' + document.location.hostname + ';';
}

Drupal.settings data

"og_oven":{"cookie_name":"og_oven","expire_time":88473600}

High performance

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: