Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/01/2015, 18:17
Avatar de JethCrew
JethCrew
 
Fecha de Ingreso: marzo-2012
Ubicación: México
Mensajes: 67
Antigüedad: 12 años, 1 mes
Puntos: 3
Problema con acortador como hacer para contar las visitas

Tengo un script acortador de enlaces pero no puedo hacerlo funcionar para que guarde las visitas cada que visitan el link acortado tengo ya lista mi tabla pero no se donde colocar o que codigo colocar para que cuenten las visitas...

Aquí el código podrían ayudarme ?

mi tabla se llama: url_hits



Código PHP:
Ver original
  1. <?php
  2.  
  3. //Incluir base de datos
  4. include('db.php');
  5.  
  6. //redirigir al enlace real si la URL se establece
  7. if (!empty($_GET['url'])) {
  8.     $redirect = mysql_fetch_assoc(mysql_query("SELECT url_link FROM urls WHERE url_short = '".addslashes($_GET['url'])."'"));
  9.     $redirect = "http://".str_replace("http://","",$redirect[url_link]);
  10.     header('HTTP/1.1 301 Moved Permanently');  
  11.     header("Location: ".$redirect);  
  12. }
  13. //
  14.  
  15. //Insertar nueva url
  16. if ($_POST['url']) {
  17.  
  18. //Conseguir cadena aleatoria de URL y añade http: // si no está lo tiene
  19. $short = substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'), 0, 3);
  20.  
  21. mysql_query("INSERT INTO urls (url_link, url_short, url_ip, url_date) VALUES
  22.  
  23.     (
  24.     '".addslashes($_POST['url'])."',
  25.     '".$short."',
  26.     '".$_SERVER['REMOTE_ADDR']."',
  27.     '".time()."'
  28.     )
  29.  
  30. ");
  31.  
  32. $redirect = "?s=$short";
  33. header('Location: '.$redirect); die;
  34.  
  35. }
  36. //
  37.  
  38. ?>
  39. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  40. <html xmlns="http://www.w3.org/1999/xhtml">
  41. <head>
  42. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  43. <title>JethCrew URL Short</title>
  44. <style type="text/css">
  45. <!--
  46. body {
  47.     font-family: Geneva, Arial, Helvetica, sans-serif;
  48.     font-size: 25px;
  49.     text-align: center;
  50. }
  51. input {
  52.     font-size: 20px;
  53.     padding: 10px;
  54. }
  55. h2 {
  56.     font-size: 16px;
  57.     margin: 0px;
  58.     padding: 0px;
  59. }
  60. h1 {
  61.     margin: 0px;
  62.     padding: 0px;
  63.     font-size: 35px;
  64.     color: #009999;
  65. }
  66. form {
  67.     margin: 0px;
  68.     padding: 0px;
  69. }
  70. h3 {
  71.     font-size: 13px;
  72.     color: #666666;
  73.     font-weight: normal;
  74. }
  75. h3 a {
  76.     color: #006699;
  77.     text-decoration: none;
  78. }
  79. table {
  80.     font-size: 13px;
  81.     background-color: #EBEBEB;
  82.     border: 1px solid #CCCCCC;
  83. }
  84. -->
  85. </style>
  86. </head>
  87.  
  88. <body>
  89.  
  90.  
  91. <h1> URL a Acortar!: </h1>
  92. <form id="form1" name="form1" method="post" action="">
  93.   <input name="url" type="text" id="url" value="http://" size="75" />
  94.   <input type="submit" name="Submit" value="Go" />
  95. </form>
  96.  
  97. <!--Muestra link recien creado-->
  98. <?php if (!empty($_GET['s'])) { ?>
  99. <br />
  100. <h2>Aquí está la URL corta: <a href="<?php echo $server_name; ?><?php echo $_GET['s']; ?>" target="_blank"><?php echo $server_name; ?><?php echo $_GET['s']; ?></a></h2>
  101. <?php } ?>
  102. <!---->
  103.  
  104. <br />
  105. <br />
  106.  
  107. </body>
  108. </html>