Ver Mensaje Individual
  #5 (permalink)  
Antiguo 14/10/2011, 17:20
Avatar de Triby
Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: El contador de visitas se pone a cero

Ups, hace mucho hice un contador con archivos de texto, pero creo que en sitios de mucho trafico no es tan eficiente y podrias probar:

Código PHP:
Ver original
  1. $fcont = false;
  2. // ********** Read current total hits
  3. if(file_exists($datdir . $curcont . '.dat')) {
  4.     // ********** be sure to read the file so the counter will not be reseted
  5.     while(!$fcont) {
  6.         $fcont=@file($datdir . $curcont . '.dat');
  7.         $curnum=intval(trim($fcont[0]));    // ***** Read total hits as well
  8.     }
  9. } else {
  10.     // ********** Is the file missing?
  11.     $curnum=0;              // ***** Start counting from 0
  12. }
  13.  
  14. // ***** Increment counter by anything you've selected in it's configuration
  15. $curnum=$curnum+$aumenta;
  16.  
  17. // ***** Store the new total hits on file
  18. $chan=fopen($datdir . $curcont . '.dat', 'w');
  19. $canWrite=false;
  20. while (!$canWrite) {
  21.     $canWrite = flock($chan, LOCK_EX); // Bloqueamos el archivo para guardar el contador
  22. }
  23. fwrite($chan, $curnum);
  24. $canWrite = flock($chan, LOCK_UN);
  25. fclose($chan);

Nota: Esto lo hice en uno de mis primeros intentos por aprender PHP, ahora es mas facil guardar con file_put_contents('archivo', 'contenido', LOCK_EX); pero lo importante es tratar de leer el archivo si es que existe y esta bloqueado.
__________________
- León, Guanajuato
- GV-Foto