Subversion Repositories vgwhois

Rev

Rev 58 | Rev 97 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 58 Rev 65
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 * IPv6 functions for PHP
4
 * IPv6 functions for PHP
5
 * Copyright 2012-2020 Daniel Marschall, ViaThinkSoft
5
 * Copyright 2012-2021 Daniel Marschall, ViaThinkSoft
6
 * Version 2020-02-28
6
 * Version 2021-05-21
7
 *
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
10
 * You may obtain a copy of the License at
11
 *
11
 *
Line 676... Line 676...
676
 
676
 
677
                global $cache_ip2bin;
677
                global $cache_ip2bin;
678
                if (isset($cache_ip2bin[$ip])) return $cache_ip2bin[$ip];
678
                if (isset($cache_ip2bin[$ip])) return $cache_ip2bin[$ip];
679
 
679
 
680
                if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false) {
680
                if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false) {
-
 
681
                        $iplong = ip2long($ip);
-
 
682
                        assert($iplong !== false);
681
                        $out = base_convert(ip2long($ip), 10, 2);
683
                        $out = base_convert((string)$iplong, 10, 2);
682
                        $cache_ip2bin[$ip] = $out;
684
                        $cache_ip2bin[$ip] = $out;
683
                        return $out;
685
                        return $out;
684
                }
686
                }
685
                if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) {
687
                if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) {
686
                        $cache_ip2bin[$ip] = false;
688
                        $cache_ip2bin[$ip] = false;
Line 711... Line 713...
711
 
713
 
712
                global $cache_bin2ip;
714
                global $cache_bin2ip;
713
                if (isset($cache_bin2ip[$bin])) return $cache_bin2ip[$bin];
715
                if (isset($cache_bin2ip[$bin])) return $cache_bin2ip[$bin];
714
 
716
 
715
                if (strlen($bin) <= 32) { // 32bits (ipv4)
717
                if (strlen($bin) <= 32) { // 32bits (ipv4)
716
                        $out = long2ip(base_convert($bin, 2, 10));
718
                        $iplong = base_convert($bin, 2, 10);
-
 
719
                        $out = long2ip(intval($iplong));
717
                        $cache_bin2ip[$bin] = $out;
720
                        $cache_bin2ip[$bin] = $out;
718
                        return $out;
721
                        return $out;
719
                }
722
                }
720
                if (strlen($bin) != 128) {
723
                if (strlen($bin) != 128) {
721
                        $cache_bin2ip[$bin] = false;
724
                        $cache_bin2ip[$bin] = false;