I am looking at setting the currency of a guest site visitor. I have the look up and currency retrieval working OK based on the individuals IP.

The problem i seem to face is how to cache the currency per site visitor and not set it for the whole site/all visitors.

A dump of craft->session shows no unique guest ids available.

Should i set a cookie for current user (IP address) and compare with cached IP?

Any slaps around the head welcome :)

  • You know your $_SESSION only contains the variables of the current active user. You can't access the session variables from other users thus you won't find any "unique" keys or something. When you store a value into the session it will be an individual value for everyone who visits your site – Robin Schambach Apr 18 '18 at 16:50
  • Assuming a user is a 1:1 equivalent to an IP address is likely a wrong assumption. You'll get many false positives for users behind NAT/DHCP (like many corporations) or for people connecting through a public proxy server. – Brad Bell Apr 18 '18 at 21:02
  • Probably not so clear in my Q but i am not assuming a 1:1 equivalence between visitor an IP but between visitor and calculated currency based on ip.Yes there is margin for error but i can't see another way of getting a visitors currency other than based on IP->countryISOcode->currency. I want the currency to set prices in users own currency. Then i want to cache the currency result for the visitor to avoid further lookups of IP - but i don't want to set the currency in cache for all visitors. – joomkit Apr 18 '18 at 22:37

Your Answer

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

Browse other questions tagged or ask your own question.