survos / ip2location-bundle
Symfony wrapper for ip2location.ip
Fund package maintenance!
kbond
Installs: 21
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.1
- ip2location/ip2location-io-php: ^1.0
- symfony/config: ^6.4 || ^7.0
- symfony/dependency-injection: ^6.4 || ^7.0
- symfony/http-kernel: ^6.4 || ^7.0
- twig/twig: ^3.4
Requires (Dev)
- phpstan/phpstan: ^1.10
- symfony/browser-kit: ^6.4 || ^7.0
- symfony/cache-contracts: ^3.4
- symfony/framework-bundle: ^6.4 || ^7.0
- symfony/phpunit-bridge: ^6.4 || ^7.0
- symfony/twig-bundle: ^6.4 || ^7.0
- symfony/var-dumper: ^6.4 || ^7.0
Suggests
- symfony/cache-contracts: Cache the lookups
- dev-main
- 1.5.210
- 1.5.209
- 1.5.208
- 1.5.207
- 1.5.206
- 1.5.205
- 1.5.204
- 1.5.203
- 1.5.202
- 1.5.201
- 1.5.200
- 1.5.199
- 1.5.198
- 1.5.197
- 1.5.196
- 1.5.195
- 1.5.194
- 1.5.193
- 1.5.192
- 1.5.191
- 1.5.190
- 1.5.189
- 1.5.188
- 1.5.187
- 1.5.186
- 1.5.185
- 1.5.184
- 1.5.183
- 1.5.182
- 1.5.181
- 1.5.180
- 1.5.179
- 1.5.178
- 1.5.177
- 1.5.176
- 1.5.175
- 1.5.174
- 1.5.173
- 1.5.172
- 1.5.171
- 1.5.170
- 1.5.169
- 1.5.168
- 1.5.167
- 1.5.166
- 1.5.165
- 1.5.164
- 1.5.163
- 1.5.162
- 1.5.161
- 1.5.160
- 1.5.159
- 1.5.158
- 1.5.157
- 1.5.156
- 1.5.155
- 1.5.154
- 1.5.153
- 1.5.152
- 1.5.151
- 1.5.150
This package is auto-updated.
Last update: 2024-04-27 16:18:51 UTC
README
Symfony Bundle for the ip2location/ip2location-io-php library, to get data from an IP address.
First, get an API key at https://www.ip2location.io/pricing and add it to .env.local
echo "IP2LOCATION_API_KEY=my-api-key" >> .env.local composer req survos/ip2location-bundle bin/console debug:config survos_ip2_location --format=yaml > config/packages/survos_ip2_location.yaml
{{ ipGeolocation(app.request.clientIp).country_code}}
By default, the bundle gets the API key from the environment. Since localhost doesn't have geolocation data, you can set a default. If you're running locally, the remote address is localhost. Get your real IP address at whatismyip.com or https://api.ipify.org?format=json
# config/packages/survos_ip2location.yaml survos_ip2_location: api_key: '%env(IP2LOCATION_API_KEY)%' localhost_ip: 8.8.8.8
Trivial but functional application
Requirements:
- Locally installed PHP 8
- Symfony CLI
- sed (to change /app to / without opening an editor)
- API Key
symfony new Ip2locationDemo --webapp && cd Ip2locationDemo echo "IP2LOCATION_API_KEY=my-api-key" >> .env.local symfony composer req survos/ip2location-bundle symfony console make:controller AppController sed -i "s|/app|/|" src/Controller/AppController.php cat <<'EOF' > templates/app/index.html.twig {% extends 'base.html.twig' %} {% block body %} {% set ip = app.request.clientIp %} {{ isLocalhost(ip) ? "<div>Localhost has no geolocation, using value from config</div>" }} Hello, visitor from {{ ipGeolocation(ip).country_name}} ) <pre>{{ ipGeolocation(ip)|json_encode(constant('JSON_PRETTY_PRINT')) }}</pre> Powered by IP2Location.io <a href="https://www.ip2location.io">IP geolocation</a> web service. {% endblock %} EOF symfony server:start -d symfony open:local