Ver Mensaje Individual
  #2 (permalink)  
Antiguo 02/11/2015, 19:03
Avatar de xfxstudios
xfxstudios
 
Fecha de Ingreso: junio-2015
Ubicación: Valencia - Venezuela
Mensajes: 2.448
Antigüedad: 8 años, 10 meses
Puntos: 263
Respuesta: Contador de visitas en php no funciona como deberia

y si lo cambias asi:
Código PHP:
Ver original
  1. <html>
  2. <head></head>
  3. <body>
  4.  
  5. <?php
  6. $conexion=mysql_connect("localhost","MI_USUARIO","MI_CLAVE") or
  7.   die("Problemas en la conexion");
  8.  
  9. mysql_select_db("MI_BASE_DE_DATOS",$conexion) or
  10.   die("Problemas en la selección de la base de datos");
  11.  
  12. $ip=$_SERVER['REMOTE_ADDR'];
  13. $fecha=date("Y-m-d");
  14. $hora=date("H:i:s");
  15. $registro=mysql_query("select * from visitas where ip='$ip' and fecha='$fecha'",$conexion) or  
  16.   die("Problemas en el select:".mysql_error());
  17. //contamos los registros encontrados
  18. $total = mysql_num_rows($registro);
  19. //si existe mostramos el error
  20. if ($total >= 1)
  21. {
  22.   echo "Usted ya visitó hoy día el sitio.<br>";
  23. }
  24. //si no continuamos
  25. else
  26. {
  27.   $registros=mysql_query("insert into visitas(ip,fecha,hora) values    ('$ip','$fecha','$hora')",$conexion)
  28.      or die("Problemas en el select:".mysql_error());
  29. }
  30. $registro=mysql_query("select count(*) as cantidad from visitas",$conexion) or
  31.   die("Problemas en el select:".mysql_error());
  32. $reg=mysql_fetch_array($registro);
  33. echo "Cantidad de visitas:".$reg['cantidad'];
  34. ?>
  35. </body>
  36. </html>

otra cosa debes adaptar tu codigo a mysqli porque mysql esta sin soporte ya y puedes tener ciertos problemillas a futuro. Saludos
__________________
[email protected]
HITCEL