Foros del Web » Programando para Internet » PHP »

Reducir enlaces con Xikito

Estas en el tema de Reducir enlaces con Xikito en el foro de PHP en Foros del Web. Hola amigos, antes que caducara el sitio de este magnífico reductor de enlaces gratuito(Xiki.to), pude obtener el código que ellos ofrecían gratuitamente. Intente ajustarlo a ...
  #1 (permalink)  
Antiguo 26/10/2010, 12:58
 
Fecha de Ingreso: julio-2007
Mensajes: 287
Antigüedad: 16 años, 8 meses
Puntos: 4
Reducir enlaces con Xikito

Hola amigos, antes que caducara el sitio de este magnífico reductor de enlaces gratuito(Xiki.to), pude obtener el código que ellos ofrecían gratuitamente.

Intente ajustarlo a mis necesidades pero no me resulto.
Los enlaces al parecer los reduce bien pero al intentar acceder por el enlace reducido no funciona.

Lo otro es que hay que crear un par de tablas para guardar algunos datos como:

ip, url, un campo id autoincrementable y un campo xclave queno supe para que sirve.

Les dejo acá el código a ver si alguien más puede cooperar y hacerlo funcionar correctamente indicando cómo.

Dejaré acá también el código pa crear las tablas por si quieren probarlo.

CREATE TABLE `log` (
`id` int(11) NOT NULL auto_increment,
`xip` varchar(15) default NULL,
`xtype` varchar(1) default NULL,
`xid` int(11) default NULL,
`xdate` datetime default NULL,
PRIMARY KEY (`id`)
)

CREATE TABLE `urls` (
`xid` int(11) NOT NULL auto_increment,
`xclave` varchar(32) default NULL,
`xurl` varchar(65000) default NULL,
`xip` varchar(15) default NULL,
PRIMARY KEY (`xid`)
)
Código PHP:
Ver original
  1. <?php
  2. # index.php - Main Index File
  3. #
  4. # Copyright (c) 2008 Julian Coccia
  5. # Licensed under the GNU GPL. For full terms see the file COPYING.
  6. # Bajo licencia GNU GPL. Consulte el fichero anexo COPYING.
  7. #
  8. # http://xiki.to
  9. #
  10.  
  11. $dbh=mysql_connect ("localhost", "username", "password") or die('Error en la base de datos');
  12. mysql_select_db ("database");
  13.  
  14. $str1="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  15. $str2="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  16. $str3="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  17.  
  18. function xlog($type,$codigo) {
  19.  
  20.     mysql_query("INSERT INTO urls SET xdate=now(), xtype=\"$type\", xid=$codigo , xip=\"".$_SERVER['REMOTE_ADDR']."\"");
  21.  
  22. }
  23.  
  24. function headers() {
  25.  
  26. ?>
  27. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  28.                       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  29. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
  30. <head>
  31.  <title>Xikito - Reduce tu enlace</title>
  32.  <style type="text/css" media="all">
  33.   @import url("/style.css");
  34.  </style>
  35.  <link rel="icon" type="image/x-icon" href="/favicon.ico">
  36.  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  37. </head>
  38. <body>
  39. <br />
  40. <div id="logo">
  41. <a href="http://xiki.to" title="xikito reduce tu enlace"><img src="xikito.png" alt="xikito reduce tu enlace"></a>
  42. </div>
  43. <?php
  44.  
  45. }
  46.  
  47. function footer() {
  48.  
  49. ?>
  50. <div id="xikito">
  51. Arrastra Xikito a la barra de tu navegador y convierte tus enlaces con un solo click:
  52. <a href="javascript:void(location.href='http://xiki.to/?url='+encodeURIComponent(location.href))">Xikito</a><br />
  53. </div>
  54. </body>
  55. </html>
  56. <?php
  57.  
  58. }
  59.  
  60. function deco($codigo) {
  61.  
  62.     global $str1,$str2,$str3;
  63.     $v1=strpos($str3,substr($codigo,0,1));
  64.     $v2=strpos($str2,substr($codigo,1,1));
  65.     $v3=strpos($str1,substr($codigo,2,1));
  66.     return ($v1+$v2*62+$v3*3844);
  67.  
  68. }
  69.  
  70. function codi($numero) {
  71.  
  72.     global $str1,$str2,$str3;
  73.     $v3=0;
  74.  
  75.     if ($numero >= 3844) {
  76.         $v3 = ($numero-($numero % 3844))/3844;
  77.     }
  78.  
  79.     $resto= ($numero - ($v3 * 3844));
  80.     $v2=0;
  81.  
  82.     if ($resto >= 62) {
  83.         $v2 = ($resto-($resto % 62))/62;
  84.     }
  85.  
  86.     $v1=$numero-($v3*3844)-($v2*62);
  87.     return substr($str3,$v1,1).substr($str2,$v2,1).substr($str1,$v3,1);
  88.  
  89. }
  90.  
  91.  
  92. # REDIRECT
  93. #
  94. $codigo=substr($_GET["codigo"],0,3);
  95. if ($codigo) {
  96.  
  97.         $res=mysql_query("SELECT xurl FROM urls WHERE xid=".deco($codigo)) or die ("Error: ".mysql_error());
  98.         if (mysql_affected_rows()) {
  99.         xlog("R",$codigo);
  100.         header("Location: ".mysql_result($res,0), true, 301);
  101.         }
  102.  
  103.         else {
  104.         xlog("E",$codigo);
  105.         headers();
  106.                 print "<div id='aviso'>El enlace xikito todav&iacute;a no existe!</div>";
  107.         }
  108.  
  109.     footer();
  110.         exit;
  111. }
  112.  
  113.  
  114. headers();
  115. # ADD URL
  116. #
  117. $url=str_replace("\"","%22",$_GET["url"]);
  118. if ($url) {
  119.  
  120.     # Check if starts with http://
  121.     if ((substr(strtolower($url),0,7)<>"http://") && (substr(strtolower($url),0,7)<>"ftp://")) {
  122.         $url="http://".$url;
  123.     }
  124.    
  125.     # Set domain name to lowercase
  126.     $barra=strpos($url."/","/",7);
  127.     $url=strtolower(substr($url,0,$barra)).substr($url,$barra);
  128.  
  129.     if ("http://xiki.to" != substr($url,0,14)) {
  130.        
  131.         # Check if URL exists
  132.         $res=mysql_query("SELECT xid FROM urls WHERE xurl=\"$url\"");
  133.         if (mysql_affected_rows()) {
  134.             $codigo=mysql_result($res,0);
  135.         }
  136.  
  137.         # Insert URL
  138.         else {
  139.             $ip=$_SERVER['REMOTE_ADDR'];   
  140.             mysql_query("INSERT INTO urls SET xurl=\"$url\", xip=\"$ip\"");
  141.             $codigo=mysql_insert_id();
  142.         }
  143.         print "<div id='aviso' style='text-align: left;'>";
  144.         print "<b>Tu enlace xikito ha sido creado!</b><br />";
  145.         print "http://xiki.to/".codi($codigo)."<br />";
  146.         print "<a href='http://xiki.to/".codi($codigo)."' target='_blank'>abrir</a>";
  147.         print "</div>";
  148.  
  149.         xlog("I",$codigo);
  150.         footer();
  151.         exit;
  152.     }
  153. }
  154.  
  155. ?>
  156.  
  157. <form action="" method="get">
  158. Pega aqu&iacute; tu enlace<br>
  159. <input type="text" name="url" size="28"><input type="submit" value="hacer xikito">
  160. </form>
  161.  
  162. <?php
  163. footer();
  164. ?>

Etiquetas: enlaces, reducir
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:19.