Closed (fixed)
Project:
IP to Country
Version:
5.x-1.0
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
25 Oct 2007 at 00:54 UTC
Updated:
12 Nov 2007 at 22:42 UTC
I'm trying to use this module to display different information in a block on my homepage based on the visitor's country.
It works, but only the first time the homepage is accessed. Then the homepage gets cached and subsequent visitors see the cached version which was based on the country of the first visitor.
Disabling page caching is not an option due to performance considerations.
I'm not sure there is really anything that can be done about this on the server - perhaps you could add an ajax capability so that the country can be determined in javascript after the cached page has loaded, and I can hide the data I don't want to show using javascript?
Comments
Comment #1
mr.j commentedAlright this bugged me enough to roll my own solution so here it is.
Apologies for no patch file, but the additions to the module are so minor it should be easy to do.
First up, add this snippet to the ip2cc_menu() function in the module. It sets up a menu callback that allows us to call ip2cc using the path "http://www.yoursite.com/ip2cc_get_country_js". It won't appear a menu anywhere - its just drupal's way of allowing you to map a custom URL to a php callback.
Now add the callback function we defined above elsewhere in the module. The function returns the whole $country object as a json string, which can later be converted to a javascript object on the client.
So now if you want to call this callback using ajax on your page or block its quite simple. This is part of a bit of php I have inserted into a block. My block displays two tabs, and I want one of them initially selected for US visitors, and the other for everyone else:
What it does is calls that callback function we added to the module via ajax when the page loads and the callback returns a json string, which we then eval() into a javascript object. Works like a charm.
I highly recommend that this is added to the module code.
Comment #2
sugree commentedGreat idea! I adjusted your patch a little bit. The url is changed to "ip2cc/get_country/json".
Comment #3
(not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.