ipinfo / php Goto Github PK
View Code? Open in Web Editor NEWOfficial PHP library for IPinfo (IP geolocation and other types of IP data)
Home Page: https://ipinfo.io
License: Apache License 2.0
Official PHP library for IPinfo (IP geolocation and other types of IP data)
Home Page: https://ipinfo.io
License: Apache License 2.0
It seems that it does not work with PHP 8.2+. Creating a dynamic property is deprecated.
Deprecated: Creation of dynamic property ipinfo\ipinfo\Details::$carrier is deprecated in XXX/vendor/ipinfo/ipinfo/src/Details.php on line 40 PHP Deprecated: Creation of dynamic property ipinfo\ipinfo\Details::$carrier is deprecated in XXX/vendor/ipinfo/ipinfo/src/Details.php on line 40
This failure cost us 817.487 api calls :-(
I'm wanting to go live with a production machine but I'm getting more time-out errors. It doesn't exit gracefully and causes an error. If you refresh the page it works.
The error is:
[06-Jun-2024 19:46:10 Africa/Johannesburg] PHP Fatal error: Uncaught ipinfo\ipinfo\IPinfoException: cURL error 28: Connection time-out (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://ipinfo.io/162.243.34.10 in /home/andrebruton/domain.co.za/vendor/ipinfo/ipinfo/src/IPinfo.php:239
Stack trace:
#0 /home/andrebruton/domain.co.za/vendor/ipinfo/ipinfo/src/IPinfo.php(98): ipinfo\ipinfo\IPinfo->getRequestDetails('162.243.34.10')
#1 /home/andrebruton/domain.co.za/shop/index.php(76): ipinfo\ipinfo\IPinfo->getDetails('162.243.34.10')
Introduced in #7
Hi, I am using the package to get info about a specific ip, and sometimes, in a context I do not understand yet, I get empty (null) response when calling IPinfo::getDetails()
. I would like to know why it can return null (is it because the API throttle, server error, or any other reason?).
Not that no IPinfoException
is thrown, I just get null
as a result.
Also not that when I retry a few moment later the same request, it gets the result without issues.
If I know the reason I can take required measures to mitigate the issue. Thank you.
As far as I understand, this client makes api requests ещ ipinfo.io. I was wondering if I purchase a geolocation database (I need it for other purposes as well), can I somehow initialize the client with data from the database. So that it does not make any requests over the network and works only with local data?
Add an optional IP selection handler to the SDK client initialization step which accepts the request context and expects returning an IP.
Add a default handler for this which looks at the X-Forwarded-For
header and falls back to the source IP.
The resulting IP is the IP for which details are fetched.
Make sure the cache key contains a number to indicate the version of the cached data. Data changes that change what's expected in cached data require a version change.
Implement SDK support for IP summaries.
I am using PHPStorm+EA Inspections and when I am accessing any of Details
dynamic properties, I get errors like
[EA] \ipinfo\ipinfo\Details needs to implement __isset to properly work here.
when doing something like
if (empty($ipinfo->country_name)) {}
I found this explanation of the inspection. So essentially the issue is that there are no magic __get
, __set
and __isset
(and probably __unset()
for good measure). While this is not necessarily an issue, since empty()
is going to work normally, it may be a good idea to adjust the code so that inspections would not complain like this. I mean, empty()
or isset()
feel pretty reasonable operators here.
Alternative is to add all possible attributes as, well, actual attributes in the class, but I do understand that since this is API parser, it may make sense to make the attributes dynamic, so that you do not need to update things in PHP code every time the output of the API changes. On the other hand, it may help with some sanitization, in case something does go wrong with the API output.
I tried for the first time the API, with a simple symfony code I get the error:
Cache key "xxxx:1" contains reserved characters "{}()/\@:"
With xxxx
being the ip adress of my server.
$client = new IPinfo($access_token);
$details = $client->getDetails($_SERVER["REMOTE_ADDR"]);
I tried setting the ip_address myself, and always the same result, the code add a ":1" at the end of my IP.
Executing getDetails with fake IP produces fatal error.
$ip = '34535'; $IPInfoClient->getDetails($ip);
Add use \Exception;
into IPInfo.php
There are a few dynamicly created properties (IPinfo::$settings for example) which are deprecated in php 8.2
Please, add timeout option, so that we can control how long the request may work.
I am trying to retrieve my public IPv6 address but the getDetails() function, with $ip_address paramater set to null, only returns the IPv4 address. i have tried changing the const API_URL of the IPinfo class to 'https://v6.ipinfo.io' but somehow that leads to an curl error 7 which i do not understand. because if i use curl directly it works.
curl ipinfo.io/?token=mytoken
returns json with ip as ipv4 address
curl ipinfo.io/ip/?token=mytoken
returns string ip as ipv4 address
curl v6.ipinfo.io/ip/?token=mytoken
returns string ip as ipv6 address
curl https://v6.ipinfo.io/ip/?token=mytoken
returns string ip as ipv6 address
any idea why the curl error?
https://ipinfo.io/developers/batch
Take into account use cases like ipinfo/python#35 to ensure batch ops support is scalable & robust.
When you retrieve an ipv6 via getDetails
for example, it throws Symfony\Component\Cache\Exception\InvalidArgumentException
Cache key "xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx_v1" contains reserved characters "{}()/\@:".
Here is the error I get every time I run composer update.
Deprecation Notice: Class ipinfo\ipinfo\cache\CacheInterface located in ./vendor/ipinfo/ipinfo/src/cache/Interface.php does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///usr/local/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:185
Deprecation Notice: Class ipinfo\ipinfo\cache\DefaultCache located in ./vendor/ipinfo/ipinfo/src/cache/Default.php does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///usr/local/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:185
Right now caching can be modified by a settings key to choose your own cache implementation.
However it should be easier to disable caching (it should really default to disabling, but that would be a breaking change); currently that requires creating a custom cache implementation which simply does nothing.
We can either create such an implementation that does nothing, or have a new key like cache_disabled
and update cache-using code to check if the cache exists before using it.
I know that you are working on V2.0.0. This is just to mention that as your Releases page makes the impression that V2.0.0 is released. If so kindly update your Composer Package to V2.0.0.
can you update package list with the latest build?
Hi, can you please make it possible to upgrade sabre/cache to version 2.0+?
Thanks
When using a Domainname Referrer restriction on my token, the PHP library fails to fetch user details with an error
400 Bad Request
I assume this is because my script runs Serverside hence not having a referrer http header.
Any ideas how to overcome this? Like can I force pass a referrer serverside to the IPinfo Library?
Hello!
I really love IP info and recently you guys launched: Map IPs: https://ipinfo.io/map
Would it be possible to get this in the library? I was thinking of PRing it but unsure if it's more of an "experimental/fun" thing at the moment or if it's something that will stick around and is production ready.
Kind Regards!
If I use this library in a project with Guzzle7, then the following error is displayed by composer:
ipinfo/ipinfo v1.1.1 requires guzzlehttp/guzzle ^6.3 -> satisfiable by guzzlehttp/guzzle[6.3.0, 6.3.1, 6.3.2, 6.3.3, 6.4.0, 6.4.1, 6.5.0, 6.5.1, 6.5.2, 6.5.3, 6.5.4, 6.5.5, 6.5.x-dev] but these conflict with your requirements or minimum-stability.
HI,
I want to use this package into my project and my project using guzzlehttp/guzzle v7.2 and your package is require a guzzlehttp/guzzle v ^6.3 so I am unable to import package via composer
can you please update your package at packagist?
thanks
There are some features like directly getting Lattitude with $details->lattitude or $details['lattitude'] is not working, and for ipinfo.io/43.241.71.120/privacy?token=$TOKEN This part of feature is not working or I'm unable to get the result using simple php command.
The problem is that it returns a 400 error, but in the local environment it works correctly, I already configured Whitelist Referring Domains.
`
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once FCPATH.'vendor/autoload.php';
use ipinfo\ipinfo\IPinfo;
use ipinfo\ipinfo\IPinfoException;
...
$access_token = 'xxx';
$client = new IPinfo($access_token);
$ip_address = '190.129.164.188';
$details = $client->getDetails($this->ip());
echo "<pre>";
var_dump($details);
echo "</pre>";
`
ERROR
An uncaught Exception was encountered
Type: ipinfo\ipinfo\IPinfoException
Message: Exception: {"status":400,"reason":"Bad Request"}
Filename: /home3/antraxse/public_html/vendor/ipinfo/ipinfo/src/IPinfo.php
Line Number: 209
Backtrace:
Hello,
I found that it is not working with ipv6. As I am not getting location for ipv6 please update it as soon as posible
Unable to download if you have PHP 8
Output below:
Problem 1
- ipinfo/ipinfo[dev-master, v2.0.0] require php ~7.0 -> your php version (8.0.0) does not satisfy that requirement.
- ipinfo/ipinfo 2.0.x-dev is an alias of ipinfo/ipinfo dev-master and thus requires it to be installed too.
- Root composer.json requires ipinfo/ipinfo ^2.0.0 -> satisfiable by ipinfo/ipinfo[v2.0.0, 2.0.x-dev (alias of dev-master)].
In the latest PHP versions there's a Stringable interface required to be implemented by some packages before we can use certain functions properly. For example, Symfony starts requiring it to set parameters on a request:
Before: https://github.com/symfony/symfony/blob/5.4/src/Symfony/Component/HttpFoundation/InputBag.php#L80
After: https://github.com/symfony/symfony/blob/6.0/src/Symfony/Component/HttpFoundation/InputBag.php#L70
We have several files like eu.json
, countries.json
, continents.json
and so on, which are loaded during initialization / startup of the client.
Instead of loading these as such, which has risks such as the asset not appearing in a production environment properly, and has a performance penalty during init of loading an on-disk file, we should inline the files into a static, in-memory map / dictionary or similar.
Hi
I want to use it without the composer. I tried to add files with require_once
function nut it does not work. example: require_once('ipinfo/src/IPinfo.php')
can you help me?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.