Re: [phpOpenTracker-User] How to call POT more than once in a single document?

Florian Dittmer <[email protected]>
Newsgroups gmane.comp.web.phpopentracker.general
Message-ID <[email protected]>
Hi,
I have done a quick hack to the Container.php, now it seems to work the
way I want - or have I overseen something?

This might not be the best solution, but I have no experience with OO
PHP. Well, at least it _seems_ to work.

WHat I am doing is the following:
- set $myContainerID to the current client_id
- isInitialized is now an array. As index is $myContainerID used.
- The Conainer is now stored in a session variable called 
   "'_phpOpenTracker_Container'.$myContainerID" (this allowes to have   
   more than one container in a single session)

This gives the possibility to call the log() function more than once,
when using a different client_id for each call. This allowes me to
create the statistics I want, I guess ... :-)

I appended the file. If I havent forgotten, I have marked all lines I
changed with "// dittmer: ..." , but it' s not much.

The original Container.php it' s based on is from the 1.2.0 release.

Sebastian, what to you think about this? 

Greetings

Florian

PS: You also have to edit phpOpenTracker.php and change
include POT_INCLUDE_PATH . 'LoggingEngine.php';
to
include_once POT_INCLUDE_PATH . 'LoggingEngine.php';
(line 103 or something)



On Wed, 2003-07-30 at 07:24, Sebastian Bergmann wrote:
> Florian Dittmer wrote:
> > So, is there a workaround?
> 
>   No.
> 
> > Or some other, maybe better way for me to get these statistics?
> 
>   There should be a possibility. Please file a feature request about this
>   and I'll think about how to implement this for phpOpenTracker 1.3.
> 
> > Greetings
> > Florian
> 
>   Greetings,
> Sebastian
Container.php (application/x-php, 8.2 KB)
<?php
//
// +---------------------------------------------------------------------+
// | phpOpenTracker - The Website Traffic and Visitor Analysis Solution  |
// +---------------------------------------------------------------------+
// | Copyright (c) 2000-2003 Sebastian Bergmann. All rights reserved.    |
// +---------------------------------------------------------------------+
// | This source file is subject to the phpOpenTracker Software License, |
// | Version 1.0, that is bundled with this package in the file LICENSE. |
// | If you did not receive a copy of this file, you may either read the |
// | license online at http://phpOpenTracker.de/license/1_0.txt, or send |
// | a note to [email protected], so we can mail you a copy.     |
// +---------------------------------------------------------------------+
//
// $Id: Container.php,v 1.27.2.1 2003/07/09 05:53:43 bergmann Exp $
//

require POT_INCLUDE_PATH . 'Parser.php';

/**
* phpOpenTracker Session Container
*
* @author   Sebastian Bergmann <[email protected]>
* @version  $Revision: 1.27.2.1 $
* @since    phpOpenTracker 1.0.0
*/
class phpOpenTracker_Container {
  /**
  * Returns a reference to phpOpenTracker's session container.
  *
  * The first call to this method during a request triggers, if
  * $parameters['init'] is not set to false, the generation of
  * the session container array.
  *
  * @param  optional array $parameters
  * @return array
  * @access public
  * @static
  */

  function &singleton($parameters = array()) {
    static $isInitialized;

    // dittmer: get my client_id - used for storing container in session
    $myContainerID = isset($parameters['client_id'])    ? $parameters['client_id'] : 1;


    $init          = isset($parameters['init'])        ? $parameters['init']        : false;
    $initAPI       = isset($parameters['initAPI'])     ? $parameters['initAPI']     : false;
    $initNoSetup   = isset($parameters['initNoSetup']) ? $parameters['initNoSetup'] : false;

    // dittmer: we need more than one isInitialized, so use myConatinerID ;-)
    $isInitialized[$myContainerID] = isset($isInitialized[$myContainerID])             ? $isInitialized[$myContainerID]            : false;


    if ($initAPI) {
      $init          = true;
      // dittmer: use myContainerID
      $isInitialized[$myContainerID] = false;
    }

    else if ($initNoSetup) {
      $init = true;
    }

    // dittmer: Use myContainerID for Session and isInitialized
    if ($isInitialized[$myContainerID] && !$init) {
      return $_SESSION['_phpOpenTracker_Container'.$myContainerID];
    }

    // dittmer: Use myContainerID for Session
    if ($init && !$initAPI) {
      session_register('_phpOpenTracker_Container'.$myContainerID);
      $container = &$_SESSION['_phpOpenTracker_Container'.$myContainerID];
    }

    // dittmer: Use myContainerID for isInitialized
    if ($init && !$isInitialized[$myContainerID] && !$initNoSetup) {
      $config = &phpOpenTracker_Config::singleton(true);
      $db     = &phpOpenTracker_DB::singleton();

      $parameters['client_id']    = isset($parameters['client_id'])    ? $parameters['client_id'] : 1;
      $container['first_request'] = isset($container['first_request']) ? false                    : true;

      if ($container['first_request']) {
        $client_id_switched = false;
      }

      else if ($container['client_id'] != $parameters['client_id']) {
        $container['first_request'] = true;
        $client_id_switched         = true;
      }

      $container['client_id'] = $parameters['client_id'];

      if ($container['first_request']) {
        if (function_exists('posix_getpid')) {
          $container['accesslog_id'] = crc32(microtime() . posix_getpid());
        } else {
          $container['accesslog_id'] = crc32(microtime() . session_id());
        }

        if (!$client_id_switched) {
          if (!isset($parameters['host']) &&
              !isset($parameters['ip_address'])) {
            if (isset($_SERVER['REMOTE_ADDR'])) {
              $container['ip_address'] = $_SERVER['REMOTE_ADDR'];

              if (isset($_SERVER['REMOTE_HOST'])) {
                $container['host_orig'] = $_SERVER['REMOTE_HOST'];
              } else {
                if ($config['resolve_hostname']) {
                  $container['host_orig'] = gethostbyaddr($container['ip_address']);
                } else {
                  $container['host_orig'] = $container['ip_address'];
                }
              }
            } else {
              $container['host_orig']  = '';
              $container['ip_address'] = '';
            }
          } else {
            $container['host_orig']  = isset($parameters['host'])       ? $parameters['host']       : '';
            $container['ip_address'] = isset($parameters['ip_address']) ? $parameters['ip_address'] : '';
          }

          $container['host'] = $container['host_orig'];

          if ($config['group_hostnames']) {
            $container['host'] = phpOpenTracker_Parser::hostname($container['host']);
          }

          $container['user_agent_orig'] = isset($parameters['user_agent']) ? $parameters['user_agent'] : $_SERVER['HTTP_USER_AGENT'];

          if ($config['group_user_agents']) {
            $container = array_merge(
              $container,
              phpOpenTracker_Parser::userAgent($container['user_agent_orig'])
            );
          } else {
            $container['operating_system'] = 'Not identified';
            $container['user_agent']       = $container['user_agent_orig'];
          }

          $container['host_id'] = $db->storeIntoDataTable(
            $config['hostnames_table'],
            $container['host']
          );

          $container['operating_system_id'] = $db->storeIntoDataTable(
            $config['operating_systems_table'],
            $container['operating_system']
          );

          $container['user_agent_id'] = $db->storeIntoDataTable(
            $config['user_agents_table'],
            $container['user_agent']
          );
        }

        if (isset($parameters['referer'])) {
          $container['referer_orig'] = $parameters['referer'];
        } else {
          $container['referer_orig'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
        }

        $container['referer_orig'] = urldecode($container['referer_orig']);

        if ($config['clean_referer_string']) {
          $container['referer'] = preg_replace('/(\?.*)/', '', $container['referer_orig']);
        } else {
          $container['referer'] = $container['referer_orig'];
        }

        if (!empty($container['referer'])) {
          $container['referer'] = str_replace('http://', '', $container['referer']);
        }

        $container['referer_id'] = $db->storeIntoDataTable(
          $config['referers_table'],
          $container['referer']
        );
      } else {
        $container['last_document'] = $container['document'];
      }

      $container['document_url'] = isset($parameters['document_url']) ? $parameters['document_url'] : urldecode($_SERVER[$config['document_env_var']]);

      if ($config['clean_query_string']) {
        $container['document_url'] = preg_replace(
          '/(\?.*)/',
          '',
          $container['document_url']
        );
      } else {
        $filters = array_merge(
          $config['get_parameter_filter'],
          array(
            session_name()
          )
        );

        foreach ($filters as $filter) {
          $container['document_url'] = preg_replace(
            '#\?' .
            $filter .
            '=.*$|&' .
            $filter .
            '=.*$|' .
            $filter .
            '=.*&#msiU',
            '',
            $container['document_url']
          );
        }
      }

      $container['document']    = isset($parameters['document']) ? $parameters['document'] : $container['document_url'];
      $container['document_id'] = $db->storeIntoDataTable(
        $config['documents_table'],
        $container['document'],
        $container['document_url']
      );

      $container['timestamp'] = isset($parameters['timestamp']) ? $parameters['timestamp'] : time();

      // dittmer use myContainerID
      $isInitialized[$myContainerID] = true;
    }

    return $container;
  }
}

//
// "phpOpenTracker essenya, gul meletya;
//  Sebastian carneron PHP."
//
?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.