akalongman / akalongman/php-ip-tools

isRemote() is not the same as !isLocal()

Open
#8 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
147
Forks
10
PR merge metrics
No merged PRs in 30d

Description

When passing an empty string as the IP like this:
```php
$ip = '';
$is_remote = Ip::isRemote($ip);
```

it returns `true`, even thought the IP itself is invalid.

This is because `isLocal()` returns `false` (due to the IP being invalid), and `isRemote()` simply switches the result to `true`.

Workaround:
```php
$ip = '';
$is_remote = Ip::isValid($ip) && Ip::isRemote($ip);
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.