CircleDock:
How to make Emanuele's Modification only affect visitors from within the EU

As it stands, Emanuele's modification will prompt all visitors to accept cookies, regardless of where they are located in the world. This may not be desirable and could be irritable for non-EU members. There is a way around this but you will need to have Spuds' geoIP (IP to Location) modification installed as the method presented here makes use of that modification's database tables.

We will be editing just one file - Subs-EclWarning.php - which should be in your Sources directory.

Search for:

--- Code: --- global $cookiename, $modSettings;

static $storeCookies;

if (isset($storeCookies)) return $storeCookies;

--- End code ---

Replace with:

--- Code: --- global $cookiename, $modSettings;

static $storeCookies; static $inEU; // True if visitor's Point of Presence is within a EU member state

// Have we checked this visitor's Point of Presence? if (!isset($inEU)) $inEU = ecl_IsInEU(); // If he's not within the EU, he can have cookies without giving permission if (!$inEU) $storeCookies = true;

if (isset($storeCookies)) return $storeCookies;

--- End code ---

Immediately above the function ecl_authorized_cookies(), add the following code:

//// Master Function to determine whether an IP Address points to a location within the European Union.// If the geoIP modification is available and the visitor's IP Address is IPv4, then we use the geoIP// tables. IPv6 Addresses currently not catered for.//// Returns true If the ECL modification should prompt for permission to store cookies.//function ecl_IsInEU(){ global $sourcedir;

//// This function checks the geoIP database tables to determine whether a given// IPv4 Address is located within the EU. Uses code from geoIP modification.//// Parameter: $ipAddress A properly-formed IPv4 Address//// Returns: true IP Address is within the EU// false IP Address not within the EU//function ecl_geoIP($ipAddress){ global $smcFunc;

// Sanitise the result. Assume the visitor is within the EU. $row = $smcFunc['db_fetch_assoc']($request); $cc = 'EU'; // If the IP Address is not contained within a range, the next higher value will be returned. if ($row['start'] <= $ipl && $row['end'] >= $ipl) $cc = $row['cc']; $smcFunc['db_free_result']($request);

// We have the two-letter country code, does it match? $res = array_search($cc, $euNations); if ($res === false) return false; return true;}

--- End code ---

That's it folks!

A caveat and other considerations:

* This addition does not currently cater for checking the location of IPv6 Addresses and assumes any IPv6 address is within the EU.* As other countries (eg the US, Australia, New Zealand etc) enact similar cookie laws, their two-letter country codes can be added to the array $euNations* You can replace the database query with a cURL request to an external IP-to-location server.* Note that some EU member states have more than one identifiable country code (eg the UK includes 'GB', 'GG', 'IM' and "JE').* Note that I'm only testing for the presence of the geoIP modification (and hence its database), its code is not loaded and executed by this modification. If you have installed geoIP but have not updated its database, then you will need to do this.Enjoy!

emanuele:
Honestly geo location is not at all accurate, so I would strictly avoid it.

CircleDock:

--- Quote from: emanuele on May 03, 2012, 01:07:08 PM ---Honestly geo location is not at all accurate, so I would strictly avoid it.

--- End quote ---Your point is well taken but MaxMind, whose database this uses, claims it to be well over 98% accurate at the country level, which is all we're interested in. The changes I've suggested do err on the side of caution and assume the visitor is within the EU unless their IP Address shows otherwise.

There's enough hostility towards this law as it is and some EU-based Admins might well be hesitant to implement any solution that might antagonize their non-EU members and visitors.

Given that many UK Government sites employ Geo-Location, as does all the UK's television broadcasters, Amazon etc., I can not see any reason why the ICO should object or come down heavily against a Forum where its use of Geo-Location has produced an erroneous result.

Arantor:
The ICO does not itself use country based geo-location for the purposes of cookie detection and I can't see them taking it well if there is a complaint because it seems to be 'how can we avoid having to do this' which is a sign of bad faith compliance.

Geo-location where it can be used to benefit the user's experience is encouraged, or where it is required for legal compliance (e.g. content that is only licensed in certain places) but to avoid compliance with a law, is not something I'd want to argue.

emanuele:

--- Quote from: CircleDock on May 04, 2012, 12:48:44 PM ---Your point is well taken but MaxMind, whose database this uses, claims it to be well over 98% accurate at the country level, which is all we're interested in.

--- End quote ---That would leave you a 1% (well, probably less) of probability that an EU-based user will not be recognized as such.If you are lucky enough within this 1% you will not get anyone that will sue you (or report to the competent authority).

Feel free to post it, no problem, I (personally) would not include it in a package. ;)