-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated file structures to use the latest standards.
- Loading branch information
1 parent
8141a1c
commit ae42f6f
Showing
9 changed files
with
238 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,22 +7,24 @@ | |
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "IP2Location", | ||
"email": "[email protected]", | ||
"homepage": "https://www.ip2location.com" | ||
"name": "IP2Location", | ||
"email": "[email protected]", | ||
"homepage": "https://www.ip2location.com" | ||
} | ||
], | ||
"autoload": { | ||
"classmap": [ | ||
"IP2Location.php" | ||
] | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^9" | ||
"phpunit/phpunit": "^9.5" | ||
}, | ||
"require": { | ||
"php": ">=5.4.0", | ||
"php": ">=7.2", | ||
"ext-bcmath": "*", | ||
"ext-curl": "*", | ||
"ext-gmp": "*" | ||
"ext-gmp": "*", | ||
"ext-json": "*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"IP2Location\\": "src" | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace IP2Location; | ||
|
||
/** | ||
* IpTools class. | ||
*/ | ||
class IPTools | ||
{ | ||
public function isIpv4($ip) | ||
{ | ||
return (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) ? true : false; | ||
} | ||
|
||
public function isIpv6($ip) | ||
{ | ||
return (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) ? true : false; | ||
} | ||
|
||
public function ipv4ToDecimal($ip) | ||
{ | ||
if (!$this->isIpv4($ip)) { | ||
return; | ||
} | ||
|
||
return sprintf('%u', ip2long($ip)); | ||
} | ||
|
||
public function ipv6ToDecimal($ipv6) | ||
{ | ||
if (!$this->isIpv6($ipv6)) { | ||
return; | ||
} | ||
|
||
return (string) gmp_import(inet_pton($ipv6)); | ||
} | ||
|
||
public function decimalToIpv4($number) | ||
{ | ||
if (!preg_match('/^\d+$/', $number)) { | ||
return; | ||
} | ||
|
||
if ($number > 4294967295) { | ||
return; | ||
} | ||
|
||
return long2ip($number); | ||
} | ||
|
||
public function decimalToIpv6($number) | ||
{ | ||
if (!preg_match('/^\d+$/', $number)) { | ||
return; | ||
} | ||
|
||
if ($number <= 4294967295) { | ||
return; | ||
} | ||
|
||
return inet_ntop(str_pad(gmp_export($number), 16, "\0", STR_PAD_LEFT)); | ||
} | ||
} |
Oops, something went wrong.