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
<?php # index.php - Main Index File # # Copyright (c) 2008 Julian Coccia # Licensed under the GNU GPL. For full terms see the file COPYING. # Bajo licencia GNU GPL. Consulte el fichero anexo COPYING. # # http://xiki.to # $str1="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $str2="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $str3="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; function xlog($type,$codigo) { mysql_query("INSERT INTO urls SET xdate=now(), xtype=\"$type\", xid=$codigo , xip=\"".$_SERVER['REMOTE_ADDR']."\""); } function headers() { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es"> <head> <title>Xikito - Reduce tu enlace</title> <style type="text/css" media="all"> @import url("/style.css"); </style> <link rel="icon" type="image/x-icon" href="/favicon.ico"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> </head> <body> <br /> <div id="logo"> <a href="http://xiki.to" title="xikito reduce tu enlace"><img src="xikito.png" alt="xikito reduce tu enlace"></a> </div> <?php } function footer() { ?> <div id="xikito"> Arrastra Xikito a la barra de tu navegador y convierte tus enlaces con un solo click: <a href="javascript:void(location.href='http://xiki.to/?url='+encodeURIComponent(location.href))">Xikito</a><br /> </div> </body> </html> <?php } function deco($codigo) { global $str1,$str2,$str3; return ($v1+$v2*62+$v3*3844); } function codi($numero) { global $str1,$str2,$str3; $v3=0; if ($numero >= 3844) { $v3 = ($numero-($numero % 3844))/3844; } $resto= ($numero - ($v3 * 3844)); $v2=0; if ($resto >= 62) { $v2 = ($resto-($resto % 62))/62; } $v1=$numero-($v3*3844)-($v2*62); } # REDIRECT # if ($codigo) { $res=mysql_query("SELECT xurl FROM urls WHERE xid=".deco($codigo)) or die ("Error: ".mysql_error()); xlog("R",$codigo); } else { xlog("E",$codigo); headers(); print "<div id='aviso'>El enlace xikito todavía no existe!</div>"; } footer(); exit; } headers(); # ADD URL # if ($url) { # Check if starts with http:// $url="http://".$url; } # Set domain name to lowercase # Check if URL exists } # Insert URL else { $ip=$_SERVER['REMOTE_ADDR']; } print "<div id='aviso' style='text-align: left;'>"; print "<b>Tu enlace xikito ha sido creado!</b><br />"; print "http://xiki.to/".codi($codigo)."<br />"; print "<a href='http://xiki.to/".codi($codigo)."' target='_blank'>abrir</a>"; print "</div>"; xlog("I",$codigo); footer(); exit; } } ?> <form action="" method="get"> Pega aquí tu enlace<br> <input type="text" name="url" size="28"><input type="submit" value="hacer xikito"> </form> <?php footer(); ?>