New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
piwik_log_visit.location_ip is negative on 32 bit systems #668
Comments
Replying to [rjmacy](ticket:668): > In the visit.php file of Piwik_Tracker, use the function below instead of ip2long to get the right number . |
The new myip2long() function works on both 32 and 64 bit systems. |
what's the issue with the php core one? |
Matt, thanks for getting back to me. I've been using Piwik for a few weeks now and love it. I hope to produce a Plugin and write an article about it soon. I suggest doing something like |
as long as long2ip is bijective (ie. negative int give back the same IP) this is not an issue is it? |
It is an issue because the number in the database is negative and the SQL function inet_ntoa() reports a NULL value when used on it. The location_ip column should be an unsigned int and we should be using inet_aton() to store the data there. |
Matt's point is that the issue isn't impacting Piwik because PHP's long2ip() is able to handle the negative int -- arising from the fact that PHP doesn't have an unsigned int type. However, I'm not opposed to the proposed change if it make its easier for plugin authors and/or when accessing the database directly. However, changing location_ip to "int unsigned" isn't exactly non-trivial. For example, the following SQL replaces negative numbers with 0:
Assuming the aforementioned roadblock is overcome, the ip2long() wrapper can probably be simplified as:
|
I agree that this change is not simple, but currently I have to store the IP address in a new colomn in dotted decimal form in order to get data from MySQL into other systems. This means I have two columns that contain basically the same data, but one is in unusable form. My manager needs the data in a usable form. I'm introducing ten programmers to Piwik and we plan on making it our company's standard for this type of data collection. As the user base of Piwik grows I think we would want to be able to pull SQL reports out of the DB directly and not have to rely on the front end for everything. BTW, you guys are doing a great job! |
Ok, working in our favor is that location_ip is a BIGINT. We'll want to keep this as a bigint so we can store ipv6 addresses (someday). Perhaps something like the following?
|
And for consistency, the change should also be applied to caller_ip. |
Attachment: |
Attachment: |
matt: the update script has to be renamed, but otherwise I believe this patch is good to go. Please review. Before update:
After update:
|
It works great. Thanks. |
BTW the -1 was dummy data that I inserted for testing. |
vipsoft, getDottedIp could be renamed getIpString. Will the PHP call: long2ip( $visitor['location_ip'] ) - used in plugins/Live/Visitor.php - still return the original IP as expected? |
Ok. I'll rename it. Yup, long2ip() works as expected, eg long2ip(-1) and long2ip(4294967295) both return 255.255.255.255. |
lgtm ("looks good to me" that is sometimes used for successful patch reviews) |
(In [1140]) fixes #668 - store location_ip as unsigned |
(In [1350]) refs #668 - fix inconsistency between fresh install and upgrade path |
In the visit.php file of Piwik_Tracker, use the function below instead of ip2long to get the right number .
function myip2long($ip){
if (is_numeric($ip)){
return sprintf(“%u”, floatval($ip));
} else {
return sprintf(“%u”, floatval(ip2long($ip)));
}
}
The text was updated successfully, but these errors were encountered: