<?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">';
?>