PHP code example of dimchtz / clientip

1. Go to this page and download the library: Download dimchtz/clientip library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dimchtz / clientip example snippets


$client = new DimChtz\ClientIP\ClientIP();

$client = new DimChtz\ClientIP\ClientIP(array(
	'http://v4.ident.me/',
	'http://checkip.amazonaws.com/',
	'http://ipecho.net/plain',
));

$client = new DimChtz\ClientIP\ClientIP();

echo 'Visitor\'s IP: ' . $client->get_ip(false);

$client = new DimChtz\ClientIP\ClientIP();

echo 'Visitor\'s IP: ' . $client->get_ip();

$client = new DimChtz\ClientIP\ClientIP();

echo 'Visitor\'s external IP: ' . $client->get_external_ip();

$client = new DimChtz\ClientIP\ClientIP();

echo $client->is_localhost() ? 'It is localhost' : 'It is not localhost';

echo DimChtz\ClientIP\ClientIP::is_valid_ip('192.168.56.23') ? 'It is valid IP' : 'It is not valid IP';

echo DimChtz\ClientIP\ClientIP::is_valid_ipv4('192.168.56.23') ? 'It is valid IPv4' : 'It is not valid IPv4';

echo DimChtz\ClientIP\ClientIP::is_valid_ipv6('::1') ? 'It is valid IPv6' : 'It is not valid IPv6';