statistics_exit

Definition

statistics_exit()
modules/statistics/statistics.module, line 44

Description

Implementation of hook_exit().

This is where statistics are gathered on page accesses.

Code

<?php
function statistics_exit() {
  global $user;

  drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH);

  if (variable_get('statistics_count_content_views', 0)) {
    // We are counting content views.
    if ((arg(0) == 'node') && is_numeric(arg(1)) && arg(2) == '') {
      // A node has been viewed, so update the node's counters.
      $fields = array(
        'daycount' => 1,
        'totalcount' => 1,
        'nid' => arg(1),
        'timestamp' => REQUEST_TIME,
      );
      db_merge('node_counter')
        ->fields($fields)
        ->expression('daycount', 'daycount + 1')
        ->expression('totalcount', 'totalcount + 1')
        ->execute();
    }
  }
  if (variable_get('statistics_enable_access_log', 0)) {
    // Log this page access.
    db_insert('accesslog')->fields(array(
      'title' => strip_tags(drupal_get_title()),
      'path' => $_GET['q'],
      'url' => $_SERVER['HTTP_REFERER'],
      'hostname' => ip_address(),
      'uid' => $user->uid,
      'sid' => session_id(),
      'timer' => timer_read('page'),
      'timestamp' => REQUEST_TIME,
    ))->execute();
  }
}
?>
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.