Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dimchtz/clientip
Client IP detector and various IP validators
https://github.com/dimchtz/clientip
client detect ip localhost visitor
Last synced: about 1 month ago
JSON representation
Client IP detector and various IP validators
- Host: GitHub
- URL: https://github.com/dimchtz/clientip
- Owner: DimChtz
- License: mit
- Created: 2020-10-03T22:51:54.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2020-10-04T20:45:37.000Z (over 4 years ago)
- Last Synced: 2024-04-25T12:43:22.545Z (9 months ago)
- Topics: client, detect, ip, localhost, visitor
- Language: PHP
- Homepage:
- Size: 11.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP ClientIP - v0.1.0
Client IP detector and various IP validators
[![Total Downloads](https://img.shields.io/packagist/dt/dimchtz/clientip.svg)](https://packagist.org/packages/dimchtz/clientip)
[![Latest Stable Version](https://img.shields.io/packagist/v/dimchtz/clientip.svg)](https://packagist.org/packages/dimchtz/clientip)
[![Software License](https://img.shields.io/packagist/l/dimchtz/clientip.svg?style=flat-square)](https://github.com/DimChtz/ClientIP/blob/main/LICENSE)## Installation
```sh
composer require dimchtz/clientip
```## Initialization
```php
$client = new DimChtz\ClientIP\ClientIP();
```You can also add additional IP services (for the external IP detection functionality):
```php
$client = new DimChtz\ClientIP\ClientIP(array(
'http://v4.ident.me/',
'http://checkip.amazonaws.com/',
'http://ipecho.net/plain',
));
```## Usage & Examples
#### Getting client's IP (without localhost check)
```php
$client = new DimChtz\ClientIP\ClientIP();echo 'Visitor\'s IP: ' . $client->get_ip(false);
```#### Getting client's IP (with localhost check)
By default `get_ip()` will return the external IP if the user is on localhost.
```php
$client = new DimChtz\ClientIP\ClientIP();echo 'Visitor\'s IP: ' . $client->get_ip();
```#### Getting client's external IP
```php
$client = new DimChtz\ClientIP\ClientIP();echo 'Visitor\'s external IP: ' . $client->get_external_ip();
```#### Check if the visitor's IP is localhost
```php
$client = new DimChtz\ClientIP\ClientIP();echo $client->is_localhost() ? 'It is localhost' : 'It is not localhost';
```#### Check if an IP is valid (both IPv4 & IPv6)
```php
echo DimChtz\ClientIP\ClientIP::is_valid_ip('192.168.56.23') ? 'It is valid IP' : 'It is not valid IP';
```#### Check if an IP is valid IPv4
```php
echo DimChtz\ClientIP\ClientIP::is_valid_ipv4('192.168.56.23') ? 'It is valid IPv4' : 'It is not valid IPv4';
```#### Check if an IP is valid IPv6
```php
echo DimChtz\ClientIP\ClientIP::is_valid_ipv6('::1') ? 'It is valid IPv6' : 'It is not valid IPv6';
```