Programación Web y Scripting > PHP
Ayuda Con Codigo..
F_Tanori:
--- Código: Text ---<?php $bd="base"; $host="localhost"; $user="root"; $password=""; $Conexion = mysql_connect($host,$user,$password); mysql_select_db($bd, $Conexion); if(isset($_GET['enlace'])) { $link=$_GET['enlace']; if (getenv("HTTP_X_FORWARDED_FOR")) { $ip = getenv("HTTP_X_FORWARDED_FOR"); } else { $ip = getenv("REMOTE_ADDR"); } $fecha=date('Y-m-d')." 00:00:00"; $sSQL="SELECT count(*) FROM enlaces_usuarios WHERE ip='$ip' and fecha='$fecha' and id_enlace=$link"; $rs = mysql_db_query($bd,$sSQL); if ($rs) { $registros=mysql_fetch_row($rs); if ($registros[0]==0) { $sSQL="UPDATE enlaces SET clicks=clicks+1 WHERE id_enlace=$link"; $rs = mysql_db_query($bd,$sSQL); $sSQL="INSERT INTO enlaces_usuarios (id_enlace, ip, fecha, id_row) VALUES($link,'$ip','$fecha',NULL)"; $rs = mysql_db_query($bd,$sSQL); } } } $sSQL="SELECT id_enlace, descipcion, clicks FROM enlaces"; $rs = mysql_db_query($bd,$sSQL); echo "<table>"; echo "<tr><td>IP:</td><td>$ip</td><td>Clicks</td></tr>"; while($encontrado=mysql_fetch_row($rs)) { echo "<tr><td>".$encontrado[0]."</td><td><a href='?enlace=".$encontrado[0]."'>".$encontrado[1]."</a></td><td>".$encontrado[2]."</td></tr>"; } echo "</table>"; //echo '<meta http-equiv="Refresh" content="10;URL=index.php">'; ?>
<!--sql--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td>SQL </td></tr><tr><td id='CODE'><!--sql1-->CREATE TABLE enlaces (
`id_enlace` int(10) unsigned NOT NULL auto_increment,
`descipcion` varchar(20) default NULL,
`clicks` int(10) unsigned default NULL,
PRIMARY KEY (`id_enlace`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE enlaces_usuarios (
`id_enlace` int(10) unsigned NOT NULL default '0',
`ip` varchar(20) default NULL,
`fecha` datetime default NULL,
`id_row` int(10) unsigned NOT NULL auto_increment,
PRIMARY KEY (`id_row`),
KEY `FK_enlaces_usuarios_1` (`id_enlace`),
CONSTRAINT `FK_enlaces_usuarios_1` FOREIGN KEY (`id_enlace`) REFERENCES `enlaces` (`id_enlace`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
<!--sql2--></td></tr></table><div class='postcolor'><!--sql3-->
Eso funciona todo esta en un solo archivo para mayor facilidad, pero puedes separarlo, y las validaciones son superficiales, tampoco se considera la hora solo la fecha pero puede darte una idea de como hacerlo tambien puedes usar las cookies
Saludos
Navegación
[*] Página Anterior
Ir a la versión completa