PHP code example of benjamin-smith / php-ipify

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

    

benjamin-smith / php-ipify example snippets


try {
    $ip = Ipify\Ip::get();    
} catch (ConnectionError $e) {
    // If you get here, it means you were unable to reach the ipify service,
    // most likely because of a network error on your end.
} catch (ServiceError $e) {
    // If you get here, it means ipify is having issues, so the request
    // couldn't be completed :(
} catch (Exception $e) {
    // Something else happened (non-ipify related).
}
 bash
$ composer 
 php
echo Ipify\Ip::get();