Aqui les dejo tal cual como lo tengo funcionando:
TENGO TRES ARCHIVOS:
pagina1.html
pagina2.php
pagina3.php
pagina1.html
Código:
pagina 2.php<html> <head></head> <body> <a href="pagina2.php">1 - Creación de la tabla.</a><br> <a href="pagina3.php">2 - Página que cuenta la visita</a> </body> </html>
Código:
pagina3.php<?php $conexion=mysql_connect("localhost","MI_USUARIO","MI_CLAVE") or die("Problemas en la conexion"); mysql_select_db("MI_BASE_DE_DATOS",$conexion) or die("Problemas en la selección de la base de datos"); $registros=mysql_query("drop table if exists visitas",$conexion) or die("Problemas en el select:".mysql_error()); $registros=mysql_query("create table visitas ( ip varchar(12), fecha date, hora time )",$conexion) or die("Problemas en el select:".mysql_error()); header("Location: pagina1.html"); ?>
Código:
TENGO UNA TABLA LLAMADA "visitas" que esta almacenando lo siguiente:<html> <head></head> <body> <?php $conexion=mysql_connect("localhost","MI_USUARIO","MI_CLAVE") or die("Problemas en la conexion"); mysql_select_db("MI_BASE_DE_DATOS",$conexion) or die("Problemas en la selección de la base de datos"); $ip=$_SERVER['REMOTE_ADDR']; $fecha=date("Y-m-d"); $hora=date("H:i:s"); $registro=mysql_query("select * from visitas where ip='$ip' and fecha='$fecha'",$conexion) or die("Problemas en el select:".mysql_error()); if ($reg=mysql_fetch_array($registro)) { echo "Usted ya visitó hoy día el sitio.<br>"; } else { $registros=mysql_query("insert into visitas(ip,fecha,hora) values ('$ip','$fecha','$hora')",$conexion) or die("Problemas en el select:".mysql_error()); } $registro=mysql_query("select count(*) as cantidad from visitas",$conexion) or die("Problemas en el select:".mysql_error()); $reg=mysql_fetch_array($registro); echo "Cantidad de visitas:".$reg['cantidad']; ?> </body> </html>
IP fecha hora
186.89.185.2 2015-11-03 00:34:40
186.89.185.2 2015-11-03 00:34:43
186.89.185.2 2015-11-03 00:34:45
186.89.185.2 2015-11-03 00:34:49
Como les dije cada entrada a pagina3.php esta sumando una visita sin ninguna restriccion.