Giter Site home page Giter Site logo

chrislim2888 / ip2location-php-module Goto Github PK

View Code? Open in Web Editor NEW
188.0 12.0 70.0 7.29 MB

This module is a PHP module that enables the user to find the country, region, city, coordinates, zip code, ISP, domain name, timezone, connection speed, IDD code, area code, weather station code, weather station name, mobile, usage types, address type, IAB category, etc that any IP address or host name originates from.

Home Page: https://www.ip2location.com

License: MIT License

PHP 100.00%
php ip2location geolocation iplocation isp region city country ip-location ip-address

ip2location-php-module's People

Contributors

chrislim2888 avatar gbaquedano avatar gjuric avatar ip2location avatar onesvat avatar zygimantas-skinkys avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ip2location-php-module's Issues

Not able to get CountryName, RegionName, CityName due to Warning: unpack() & Warning: fread()

I am getting below warning message. Due to these, I am not able to get CountryName, RegionName, CityName & Zip code. Even i am using DB9 BIN database.

Warning: unpack(): Type C: not enough input, need 1, have 0 in D:\Xampp\htdocs\IP2Location.php on line 1118
Warning: fread(): Length parameter must be greater than 0 in D:\Xampp\htdocs\iplocation\IP2Location.php on line 1049

/*
	Default file I/O lookup
*/
$db = new \IP2Location\Database('./databases/IPV6-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE.BIN', \IP2Location\Database::FILE_IO);

$records = $db->lookup('100.19.78.92', \IP2Location\Database::ALL);

I have placed the error screenshot in the attachment.

flimp-iplocation-error

make gmp optional

In #14, it seems that ext-gmp was removed, but it's still in composer.json.

Any chance this could be optional? I'm running PHP 8.3 on the latest Ubuntu, and having a hard time installing it. I've tried

  sudo apt install php-gmp

But I get

sudo apt install php-gmp
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 php8.2-gmp : Depends: php8.2-common (= 8.2.10-2ubuntu1) but 8.2.15-1+ubuntu22.04.1+deb.sury.org+1 is to be installed
E: Unable to correct problems, you have held broken packages.

php8 compatibility

function shmop_close() is deprecated and generate warning
This function has no effect. Prior to PHP 8.0.0, this function was used to close the resource.

use shmop_close() only on version <8 should work
if(PHP_MAJOR_VERSION < 8) { shmop_close(....); }

Make the code less fragile

As far as I can tell from investigating the code I have to check the returned fields if they contain a string with the content of constants Database::INVALID_IP_ADDRESS or Database::FIELD_NOT_SUPPORTED or Database::FIELD_NOT_KNOWN.

I think the better solution would be to:

1.) Throw an exception for an Invalid IP address in the beginning so you do not have to check the validity of an IP address when fetching all of the fields.

2.) Set the field to NULL or not return it at all so that the calling code can easily check the availability of the fields by doing an isset() or is_null calls.

Do not add .BIN files in the repo

Hello,

I suggest not to include the ./databases directory in the repo as:

  • they are not useful on production
  • can and should be downloaded from sources
  • increase the library size

Also it would be great to have a reference on instanciating it through composer.

ISP does not get detected (PX4)

I use the DB PX4 and I cannot get any ISP. No mater which IP I try.
It always Shows me:
ISP Name : -

I'm using DB9 and PX4 together (but also tested single), still same issue.
When I remove the PX4 then it shows me:
ISP Name : This parameter is unavailable in selected .BIN data file. Please upgrade.

When I go to the Onlinedemo ISP get shown:
isp ip2location

Break informations request if the IP address is not found in the database

In \IP2Location\Database::lookup() function, the "$this->binSearch($ipVersion, $ipNumber)" call may return false if the IP address is not found. Nevermind, the process go ahead.

It's better to break down immediately the function by "return false;" instead to get informations for the IP address was not found in the database.

tested from original example.php file but only showed 3 fields: IP Number , IP Version, IP Address forever

After use example file failed i created 2 dynamic pages to test and also only showed 3 fields: IP Number , IP Version, IP Address forever again.

Page 1: i coded this feature to get real ip address from IP Number from databases csv:
http://trackip.org/test2.php

example: http://trackip.org/test2.php?ipnumber1=16808448&ipnumber2=16808703

after that i copied real ip from the result of this page http://trackip.org/test2.php and put in file example.php ( page 2)

Page 2: http://trackip.org/vendor/ip2location/ip2location-php/example.php?ipaddress=1.0.123.255:

code:

$db = new \IP2Location\Database('./databases/IP2LOCATION-LITE-DB11.CSV', \IP2Location\Database::FILE_IO);

$ipaddress = isset($_GET['ipaddress']) ? $_GET['ipaddress'] : '1.0.0.0';

$records = $db->lookup($ipaddress, \IP2Location\Database::ALL);

I think your code has problem, because i tested lost more a day, only test with ips existing in database. Even i used dynamic pages to test but the problem still here. Always only showed 3 fields : IP Number , IP Version, IP Address.

Please help me.

Bin file - error line 400 of ip2location.php

Hello support team,

I tried to get info with binary file ! But the php script stop because i receive an error
i receive this error in my server logs

PHP Parse error: syntax error, unexpected '[' in /home/mywebsite/public_html/ip2location/IP2Location.php on line 400

This error is in your file when i call the require_one 'ip2location/IP2Location.php';

require_once 'ip2location/IP2Location.php'; <---- code stop after this line because the error is at line 400
$db = new \IP2Location\Database('./ip2location/databases/IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE.BIN', \IP2Location\Database::FILE_IO);

What version of php should i have ?
Do you have an idea for how fix this ?

Thanks a lot !

Pascal

No licence provided

There is no licence provided in the Github however reference is made to a GPL licence in the header of the IP2Location.php file.

PX2 issues

When using this module with a PX2 database, all fields are empty except countryName. The value of countryName consists of some data separated with \u0003.

With is the correct way to use this module with a PX2 database?

Please upgrade , selected .BIN data file.

Region Name : This parameter is unavailable in selected .BIN data file. Please upgrade.
City Name : This parameter is unavailable in selected .BIN data file. Please upgrade.
Latitude : This parameter is unavailable in selected .BIN data file. Please upgrade.
Longitude : This parameter is unavailable in selected .BIN data file. Please upgrade.
Area Code : This parameter is unavailable in selected .BIN data file. Please upgrade.
IDD Code : This parameter is unavailable in selected .BIN data file. Please upgrade.
Weather Station Code : This parameter is unavailable in selected .BIN data file. Please upgrade.
Weather Station Name : This parameter is unavailable in selected .BIN data file. Please upgrade.
MCC : This parameter is unavailable in selected .BIN data file. Please upgrade.
MNC : This parameter is unavailable in selected .BIN data file. Please upgrade.
Mobile Carrier : This parameter is unavailable in selected .BIN data file. Please upgrade.
Usage Type : This parameter is unavailable in selected .BIN data file. Please upgrade.
Elevation : This parameter is unavailable in selected .BIN data file. Please upgrade.
Net Speed : This parameter is unavailable in selected .BIN data file. Please upgrade.
Time Zone : This parameter is unavailable in selected .BIN data file. Please upgrade.
ZIP Code : This parameter is unavailable in selected .BIN data file. Please upgrade.
Domain Name : This parameter is unavailable in selected .BIN data file. Please upgrade.
ISP Name : This parameter is unavailable in selected .BIN data file. Please upgrade.

PHP8.1 and ipv6 fatal error

[31-Oct-2022 09:58:50 UTC] PHP Fatal error:  Uncaught ValueError: fread(): Argument #2 ($length) must be greater than 0 in class.IP2Location.php:1602
Stack trace:
#0 class.IP2Location.php(1602): fread(Resource id #1132, 0)
#1 class.IP2Location.php(1624): IP2Location\Database->read(851651769, 0)
#2 class.IP2Location.php(1751): IP2Location\Database->readString(16)
#3 class.IP2Location.php(1104): IP2Location\Database->readCityName(21489393)
#4 ip2location-variables.php(75): IP2Location\Database->lookup('2001:67c:198c:9...', 1001)
#5 ip2location-variables.php(51): get_ip_loc_location('2001:67c:198c:9...')

IP address was:
2001:67c:198c:906:27::267

any ideas?

fread / unpack warning

PHP Warning: unpack(): Type C: not enough input, need 1, have 0 in [snip] on line 1118
PHP Warning: fread(): Length parameter must be greater than 0 in [snip] on line 1049

Using DB23 BIN file

Minimum PHP version

Hello,
Great module!
What is the minimum PHP version required to run this module?
Thanks,

`gmp_import()` in the `ipv6ToDecimal()` Function Not Working

I’m trying to use $ipTools->ipv6ToDecimal($myIP) in example.php, and I get this error despite gmp_import() being a legit built-in function of PHP:

Uncaught Error: Call to undefined function IP2Location\gmp_import()

I’m using PHP 7, and it should be supported. I’d like to know what’s going on here because I don’t think there’s anything wrong.

Required Extensions

Hello,

Does this package requires any PHP extensions like Gmp, BCMath,...?

Thanks

Exception: IP2Location\Database: Incorrect IP2Location BIN file format.

Hi
I am using the ip2location lite database.
I get this error :
Exception: IP2Location\Database: Incorrect IP2Location BIN file format. Please make sure that you are using the latest IP2Location BIN file. in /.../vendor/ip2location/ip2location-php/src/Database.php:855

How can I fix it?

Composer: Could not find package stable

PUTTY / SSH-Verbindung

$ composer create-project /ip2location-php Mein-Webverzeichnis

[InvalidArgumentException]
Could not find package /ip2location-php with stability stable.

How to fix this "This parameter is unavailable in selected .BIN data file. Please upgrade"?

Region Name : This parameter is unavailable in selected .BIN data file. Please upgrade.
City Name : This parameter is unavailable in selected .BIN data file. Please upgrade.
Latitude : This parameter is unavailable in selected .BIN data file. Please upgrade.
Longitude : This parameter is unavailable in selected .BIN data file. Please upgrade.
Area Code : This parameter is unavailable in selected .BIN data file. Please upgrade.
IDD Code : This parameter is unavailable in selected .BIN data file. Please upgrade.
Weather Station Code : This parameter is unavailable in selected .BIN data file. Please upgrade.
Weather Station Name : This parameter is unavailable in selected .BIN data file. Please upgrade.
MCC : This parameter is unavailable in selected .BIN data file. Please upgrade.
MNC : This parameter is unavailable in selected .BIN data file. Please upgrade.
Mobile Carrier : This parameter is unavailable in selected .BIN data file. Please upgrade.
Usage Type : This parameter is unavailable in selected .BIN data file. Please upgrade.
Elevation : This parameter is unavailable in selected .BIN data file. Please upgrade.
Net Speed : This parameter is unavailable in selected .BIN data file. Please upgrade.
Time Zone : This parameter is unavailable in selected .BIN data file. Please upgrade.
ZIP Code : This parameter is unavailable in selected .BIN data file. Please upgrade.
Domain Name : This parameter is unavailable in selected .BIN data file. Please upgrade.
ISP Name : This parameter is unavailable in selected .BIN data file. Please upgrade.

Getting wrong provider

Hi,

I am using DB6 database for IP2Location with IP2Location php 7 wrapper to access properties, but in case of ISP field I am getting 32K character long hex string, and I am using SHARED_MEMORY property to access IP2Location file. Can you help me resolve this issue as we need to use this parameter and some how we are not able to do this due to above issue.

Regards

IP_FROM

I have written a nice program with Python to setup .htaccess with "Deny from IP_address"
I post it here on Github: https://gist.github.com/bazooka07/5e743e2572fec54b6e1f81f60263da0a
Obviously, it can't run directly with Apache.
I wish to do the same task but in PHP.
How can I get the IP_FROM address after calling \IP2Location\Database::lookup($ip) ?

I need to get CIDR like this :
\IP2Location\Database::lookup('178.159.37.18') ---> 178.159.37.0/24
I can easily get ip_from in Python '178.159.37.0' but I can't get it with PHP

If I can get this missing part, I can do the rest
$ipNum = ip2long('178.159.37.0'); $i=32; $mask=1; while(($ipNum & $mask) == 0) {$mask *= 2; $i--;}; echo $i;

Help me , please.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.