Ver Mensaje Individual
  #7 (permalink)  
Antiguo 09/12/2010, 21:18
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: Hacer seguimiento tráfico interno

Esto es algo muy básico

loguear.php

Código PHP:
Ver original
  1. <?php
  2. $archivo_log = "logs.html";
  3. $formato_fecha = date('d/m/Y  h:i');
  4.  
  5.     $logfileHeader='
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
  7. <html>
  8. <head>
  9.   <title>Log de visitas</title>
  10.   <link href="style.css" rel="stylesheet" type="text/css" />
  11. </head>
  12. <body>
  13.  <table cellpadding="0" cellspacing="1">
  14.    <tr><th>FECHA</th><th>IP</th><th>HOST</th><th>BROWSER</th><th>URI</th><th>REFERRER</th></tr>'."\n";
  15.  
  16.     $userAgent = (isset($_SERVER['HTTP_USER_AGENT']) && ($_SERVER['HTTP_USER_AGENT'] != "")) ? $_SERVER['HTTP_USER_AGENT'] : "N/A";
  17.     $userIp    = (isset($_SERVER['REMOTE_ADDR'])     && ($_SERVER['REMOTE_ADDR'] != ""))     ? $_SERVER['REMOTE_ADDR']     : "N/A";
  18.     $refferer  = (isset($_SERVER['HTTP_REFERER'])    && ($_SERVER['HTTP_REFERER'] != ""))    ? $_SERVER['HTTP_REFERER']    : "N/A";
  19.     $uri       = (isset($_SERVER['REQUEST_URI'])     && ($_SERVER['REQUEST_URI'] != ""))     ? $_SERVER['REQUEST_URI']     : "N/A";
  20.  
  21.     $hostName   = gethostbyaddr($userIp);
  22.     $fecha_actual = date($formato_fecha);
  23.  
  24.     $entrada = " <tr><td>$fecha_actual</td><td>$userIp</td><td>$hostName</td><td>$userAgent</td><td>$uri</td><td>$refferer</td></tr>\n";
  25.  
  26.     if (!file_exists($archivo_log)) {
  27.         $logFile = fopen($archivo_log,"w");
  28.         fwrite($logFile, $logfileHeader);
  29.     }
  30.     else {
  31.         $logFile = fopen($archivo_log,"a");
  32.     }
  33.  
  34.     fwrite($logFile,$entrada);
  35.     fclose($logFile);
  36. ?>


estilo.css

Código CSS:
Ver original
  1. table{
  2.   background:#bbb;
  3.   border:0px;
  4. }
  5.  
  6. td{
  7.   background:#fff;
  8.   color:#888;
  9.   padding:3px;
  10. }
  11. th{
  12.   background:#ccc;
  13.   color:#333;
  14.   padding:3px;
  15.   font-family: Arial, Helvetica, sans-serif;
  16. }

y en las páginas que quieras rastrear

Código HTML:
Ver original
  1. include($_SERVER['DOCUMENT_ROOT']. "/loguear.php");

con las rutas adecuadas.

Pero te aclaro, hacer que ademas cuente los hits a cada página, requiere un código más complejo.
No es tan sencillo como crees,

La aplicación http://www.bbclone.de/, no implica mucha más sobrecarga, es completamente configurable, tu decides que páginas debe o no rastrear y proporciona información mucho más precisa. y a mi juicio al menos (y en función de mis necesidades por supuesto), mucho más fácil de analizar que Google Analitycs.

saludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.