PHP code example of lindelius / php-checkip

1. Go to this page and download the library: Download lindelius/php-checkip 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/ */

    

lindelius / php-checkip example snippets


use Lindelius\CheckIp\Exception\IpCheckerException;
use Lindelius\CheckIp\IpAddress;
use Lindelius\CheckIp\IpChecker\AwsIpChecker;

$ipChecker = new AwsIpChecker(
    new \GuzzleHttp\Client(["verify" => false]),
    new \GuzzleHttp\Psr7\HttpFactory(),
    // <-- Optional PSR compatible logger
);

try {
    /** @var IpAddress $ipAddress */
    $ipAddress = $ipChecker->checkIp();
    
    echo $ipAddress->value; // A valid IPv4 or IPv6 address
    echo $ipAddress->type->value; // ipv4 | ipv6
} catch (IpCheckerException $ex) {
    // TODO: Handle potential errors
}

composer