francodacosta / grav-plugin-page-stats

better page stats for Grav
MIT License
7 stars 4 forks source link

I have an error when visit a page #25

Closed Mlimaa18 closed 1 year ago

Mlimaa18 commented 2 years ago

The plugin has this error in log. grav.ERROR: PageStats plugin : unpack(): Type V: not enough input, need 4, have 0

Also the page "top-countries" appears as "top-countries copy.md" so it generates an error when accessing from the administration panel

francodacosta commented 2 years ago

hi @Mlimaa18 can you share the full output of the error plase ?

version 2.3.0 should fix the top countries issue

Mlimaa18 commented 2 years ago

C:\wamp64\www\grav\user\plugins\page-stats\vendor\ip2location\ip2location-php\IP2Location.php

        return [6, $result];
    }
    // Invalid IP address, return falses
    return [false, false];
}

/**
 * Return the decimal string representing the binary data given.
 *
 * @static
 *
 * @param string $data Binary data to parse
 *
 * @return string
 */
private static function bcBin2Dec($data)
{
    $parts = [
    unpack('V', substr($data, 12, 4)),
    unpack('V', substr($data, 8, 4)),
    unpack('V', substr($data, 4, 4)),
    unpack('V', substr($data, 0, 4)),
];

    foreach ($parts as &$part) {
        if ($part[1] < 0) {
            $part[1] += 4294967296;
        }
    }

    $result = bcadd(bcadd(bcmul($parts[0][1], bcpow(4294967296, 3)), bcmul($parts[1][1], bcpow(4294967296, 2))), bcadd(bcmul($parts[2][1], 4294967296), $parts[3][1]));

    return $result;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Caching backend abstraction  /////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Arguments "unpack(): Type V: not enough input, need 4, have 0"

I tested in a new project only with the admin plugin and three test pages, I miss something? Thank for your help

francodacosta commented 2 years ago

hummm, that's an error with a 3rd party library.

Let me see if we can ignore it or work around it

francodacosta commented 2 years ago

@Mlimaa18 I found a similar issue on the 3rd party issue tracker https://github.com/chrislim2888/IP2Location-PHP-Module/issues/27 , they say it is because the db is corrupted

can you try to re download https://github.com/francodacosta/grav-plugin-page-stats/blob/master/data/IP2LOCATION-LITE-DB3.BIN and put it in /user/plugins/page-stats/data/IP2LOCATION-LITE-DB3.BIN ?

Mlimaa18 commented 2 years ago

Sorry, I couldn't test before. I replaced the file "IP2LOCATION-LITE-DB3.BIN" as you mentioned but it shows the same error

francodacosta commented 2 years ago

@Mlimaa18 have you updated to the latest version ? it should happily ignore the error (but log it) so it won't affect your site

This error is from the geolocation library, do you know what IP is causing the issue ?

Mlimaa18 commented 2 years ago

Yes, I updated to the last version and enable the ignore errors because I had disabled. The pages loaded well but the plugin show the stats empty. image

francodacosta commented 1 year ago

I have feeling this might be an issue with getting the ip, or the ip is coming in the wrong format.

I will add more debug code for you to try and then send me the error message

francodacosta commented 1 year ago

Can you try https://github.com/francodacosta/grav-plugin-page-stats/releases/tag/2.4.0 and send me the logs

I'm logging the ip now, should help me pin point the issue

Mlimaa18 commented 1 year ago

I'm sorry, I couldn't verify before but with the new version I was able to visualize all the statistics well. Thank you