PHP code example of palauaandsons / cloudflare-geoip
1. Go to this page and download the library: Download palauaandsons/cloudflare-geoip 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/ */
palauaandsons / cloudflare-geoip example snippets
namespace App\Http\Controllers;
use PalauaAndSons\CloudflareGeoIp\Facades\GeoIp;
use App\Models\Users;
class RegisterController extends Controller {
public function __invoke(): User
{
$location = GeoIp::getLocation();
return User::create([
'register_ip' => $location->ip
]);
}
}
\PalauaAndSons\CloudflareGeoIp\Location {
+ip: "192.182.88.29"
+city: "New Haven"
+country: "US"
+continent: "NA"
+latitude: 41.31
+longitude: -72.92
+postalCode: "06510"
+region: "Connecticut"
+regionCode: "CT"
+timezone: "America/New_York"
// pseudo fields
+iso_code: 'US' // same as country
+isoCode: 'US' // same as country
+state: 'CT' // same as regionCode
+state_name: 'Connecticut' // same as region
+stateName: 'Connecticut' // same as region
+postal_code: '06510' // same as postal_code
+lat: '41.31' // same as latitude
+lon: -72.92 // same as longitude
+toArray(): array
}
sh
php artisan vendor:publish --tag=cloudflare-geoip-config
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.