Index: modules/statistics.module =================================================================== RCS file: /cvs/drupal/drupal/modules/statistics.module,v retrieving revision 1.196 diff -u -r1.196 statistics.module --- modules/statistics.module 7 Jun 2005 18:54:37 -0000 1.196 +++ modules/statistics.module 13 Jun 2005 23:16:26 -0000 @@ -308,6 +308,18 @@ * Menu callback; presents the "referrer" page. */ function statistics_top_referrers() { + // + // $_SERVER['HTTP_HOST'] may contain a trailing port designation. + // For example: http://www.domain.tld:80 + // If this is the case, then MySQL will not properly distinguish + // between internal and external referers. + // + $http_host = $_SERVER['HTTP_HOST']; + $colon_position = strrpos($http_host, ':'); + if ($colon_position !== FALSE) { + $http_host = substr($http_host, 0, $colon_position-1); + } + $query = "SELECT url, COUNT(url) AS hits, MAX(timestamp) AS last FROM {accesslog} WHERE url NOT LIKE '%%%s%%' AND url <> '' GROUP BY url"; $query_cnt = "SELECT COUNT(DISTINCT(url)) FROM {accesslog} WHERE url <> '' AND url NOT LIKE '%%%s%%'"; drupal_set_title(t('Top referrers in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200))))); @@ -319,7 +331,7 @@ ); $query .= tablesort_sql($header); - $result = pager_query($query, 30, 0, $query_cnt, $_SERVER['HTTP_HOST']); + $result = pager_query($query, 30, 0, $query_cnt, $http_host); while ($referrer = db_fetch_object($result)) { $rows[] = array($referrer->hits, ''. check_plain(_statistics_column_width($referrer->url)) .'', t('%time ago', array('%time' => format_interval(time() - $referrer->last))));