Quote:
Originally Posted by empire10
Unfortunately this does not work anymore in 4.2. Is there any other workaround to use?
|
I've just hacked together the following, which seems to be working (in vB 4.2):
PHP Code:
function FixIPv6($ip) {
// No colon = No IPv6 (return unaltered)
if (stristr($ip,':') === false)
return $ip;
// Remove IPv6 encapsulation from IPv4 address
if (strtolower(substr($ip,0,7)) == '::ffff:')
return substr($ip,7);
// Else: Pack IPv6 address into IPv4 address
$crc = sprintf('%x',crc32($ip));
$b = ord(pack('H*',substr($crc,0,2)));
$c = ord(pack('H*',substr($crc,2,2)));
$d = ord(pack('H*',substr($crc,4,2)));
$ip = '10.'.$b.'.'.$c.'.'.$d;
return $ip;
}
$_SERVER['REMOTE_ADDR'] = FixIPv6($_SERVER['REMOTE_ADDR']);
$this->ipaddress = FixIPv6($this->ipaddress);
Put above code somewhere in
/includes/config.php (the normal vB config file), for example just before the last line (with
?>).
Warning: you might want to make a backup of the config file as messing up editing it will probably cause your forum to stop loading (just blank pages).
I'm also not 100% sure if putting the hack in config.php is quite the right location, as ideally it should of course be run before any vB code that uses IP addresses. But (in v4.2) at least the config file is included (executed) right before the
IPADDRESS constant is defined (from the
$this->ipaddress variable), so it should work alright.
My main motivation for trying to put it in the config file is that you can now easily upgrade your forum without the need to re-apply the hacks to
init.php (which the plugin does require every time).
Note that in my solution I've changed the way IPv6 addresses are encoded; so encoded IPv6 will not look the same as the plugin.