aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2016-02-16 14:56:32 +0100
committerplegall <plg@piwigo.org>2016-02-16 14:56:32 +0100
commit1fe2631774ad01f2f0e6301dc278f17122569998 (patch)
treee06ffb41f1d0e255dbf0f784aafd86ac8e941637 /include
parenta9a17a27cb75155a5bb798495e801840735ea215 (diff)
fixes #290, avoid error on MySQL insert with ipv6
Diffstat (limited to 'include')
-rw-r--r--include/functions.inc.php13
1 files changed, 12 insertions, 1 deletions
diff --git a/include/functions.inc.php b/include/functions.inc.php
index 0f26fde77..018747817 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -434,6 +434,17 @@ function pwg_log($image_id = null, $image_type = null, $format_id = null)
$tags_string = implode(',', $page['tag_ids']);
}
+ $ip = $_SERVER['REMOTE_ADDR'];
+ // In case of "too long" ipv6 address, we take only the 15 first chars.
+ //
+ // It would be "cleaner" to increase length of history.IP to 50 chars, but
+ // the alter table is very long on such a big table. We should plan this
+ // for a future version, once history table is kept "smaller".
+ if (strpos($ip,':') !== false and strlen($ip) > 15)
+ {
+ $ip = substr($ip, 0, 15);
+ }
+
$query = '
INSERT INTO '.HISTORY_TABLE.'
(
@@ -454,7 +465,7 @@ INSERT INTO '.HISTORY_TABLE.'
CURRENT_DATE,
CURRENT_TIME,
'.$user['id'].',
- \''.$_SERVER['REMOTE_ADDR'].'\',
+ \''.$ip.'\',
'.(isset($page['section']) ? "'".$page['section']."'" : 'NULL').',
'.(isset($page['category']['id']) ? $page['category']['id'] : 'NULL').',
'.(isset($image_id) ? $image_id : 'NULL').',