I have an external non-Drupal website members.example.com that sets a cookie if the audience member logs in on that site. It sets a cookie that is visible to the Drupal site that is:
$_COOKIE[‘name’] = ‘John Smith’;
I want to recognize that the members.example.com logged-in user has access to premium content on the Drupal site at http://www.example.com. I also want to great the logged-in member by name in the eyebrow section of the website.
The issue is, that after logging in the non-Drupal site members.example.com, and returning to the Drupal site http://www.example.com, Drupal is still caching a lot of stuff and doesn’t recognize that the user now has the $_COOKIE[‘name’] set.
I have:
Set the cookie domain in settings.php to ‘example.com’
Tried to bust the cache for anonymous Drupal users who also have the cookie this:
/**
* Implements hook_init()
*/
function caplogin_init() {
// Check for cookie if it's set to 'loggedout':
if (isset($_COOKIE['name'])) {
if (strpos($_COOKIE['name'],'loggedout') !== FALSE) {
// Log them out on the www site too:
setcookie('name', '', 1, '/', '.example.com');
global $user;
if ($user->uid > 0) {
user_logout();
}
$reason = 'Members server logout.';
_caplogin_no_cache($reason);
drupal_set_message(t('You have been logged out of the site. Thanks for visiting!'));
}
else {
$reason = 'Member logged in internal server.';
_caplogin_no_cache($reason);
}
}
}
and…
function _caplogin_no_cache($reason) {
if (!$reason) {
$reason = 'no-cache called by site functionality.';
}
drupal_add_http_header('X-DRCC-No-Cache-Reason', $reason);
drupal_add_http_header('Pragma', 'no-cache');
drupal_add_http_header('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT');
drupal_add_http_header('Cache-Control', 'no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0');
drupal_add_http_header('Expires', 'Sat, 02 Jan 1971 00:00:00 GMT');
}
I have also installed Devel module and (for testing) checked the ON checkbox for rebuilding the theme cache on every page load. No luck.
If you add a bogus query string it DOES bust the cache, e.g. http://www.example.com/?sdjaSDH
But the client needs the functionality where Drupal recognizes that the user has logged in the external members.example.com site.
What else can I try?
does this
help ?
You might need to add this code to hook_boot() or hook_init() with some switches of your desire.