Plugin Directory

Changeset 1066221


Ignore:
Timestamp:
01/12/2015 05:32:56 PM (11 years ago)
Author:
jonscaife
Message:

Fix for servers supporting ipv4 & ipv6

Location:
worldcurrency/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • worldcurrency/trunk/readme.txt

    r1066207 r1066221  
    55Requires at least: 2.8.0
    66Tested up to: 4.1
    7 Stable tag: 1.19
     7Stable tag: 1.20
    88
    99Recognises users by IP address and shows them converted values in their local currency, you can write post/pages in multiple currencies.
     
    9898== Changelog ==
    9999
     100= 1.20 (12 January 2015) =
     101* Fix: Fix for servers which are ipv6 and ipv4, converts all visitor addresses to pure ipv4 format.  Plugin has no support for native ipv6 at this time (the ip2c database is ipv4 only)
     102
    100103= 1.19 (12 January 2015) =
    101104* Fix: Corrected error in readme
  • worldcurrency/trunk/worldcurrency.php

    r1066207 r1066221  
    44Plugin URI: http://www.cometicucinoilweb.it/blog/en/worldcurrency-plugin-for-wordpress/
    55Description: Recognises users by IP address and shows them converted values in their local currency, you can write post/pages in multiple currencies.
    6 Version: 1.19
    7 Date: 12 Jamuary 2015
     6Version: 1.20
     7Date: 12 January 2015
    88Author: Daniele Tieghi
    99Author URI: www.cometicucinoilweb.it/blog/en/who-we-are/daniele-tieghi/
     
    224224            require_once dirname(__FILE__).'/ip2c/ip2c.php';
    225225
     226            // Known prefix
     227            $v4mapped_prefix_hex = '00000000000000000000ffff';
     228            $v4mapped_prefix_bin = pack("H*", $v4mapped_prefix_hex);
     229
     230            // Or more readable when using PHP >= 5.4
     231            # $v4mapped_prefix_bin = hex2bin($v4mapped_prefix_hex);
     232
     233            // Parse
     234            $addr = $_SERVER['REMOTE_ADDR'];
     235            $addr_bin = inet_pton($addr);
     236            if( $addr_bin === FALSE ) {
     237              // Unparsable? How did they connect?!?
     238              die('Invalid IP address');
     239            }
     240
     241            // Check prefix
     242            if( substr($addr_bin, 0, strlen($v4mapped_prefix_bin)) == $v4mapped_prefix_bin) {
     243              // Strip prefix
     244              $addr_bin = substr($addr_bin, strlen($v4mapped_prefix_bin));
     245            }
     246
     247            // Convert back to printable address in canonical form
     248            $addr = inet_ntop($addr_bin);
     249
    226250            $ip2c = new ip2country();
    227             $res = $ip2c->get_country($_SERVER['REMOTE_ADDR']);
     251            $res = $ip2c->get_country($addr);
    228252
    229253            if ($res == false) {
Note: See TracChangeset for help on using the changeset viewer.