<p>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.</p>

<p>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.</p>

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

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

<p>Any slaps around the head welcome :)</p>

CC BY-SA 3.0
2018-04-18T16:50:17.520Z
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
CC BY-SA 3.0
2018-04-18T21:02:55.647Z
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
CC BY-SA 3.0
2018-04-18T22:37:09.780Z
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
<cache><cookies>
How to cache location per guest in craft cache via plugin
# How to cache location per guest in craft cache via plugin

(Asked by: username_0 on 2018-04-18)

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 :)

**Tags:** cache, cookies

> **Comments:**
> **username_1**: 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  
> **username_2**: 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.  
> **username_0**: 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.  

---

## 0 answers

