URL缩短器如何计算URL密钥?它们如何工作? [英] How do URL shortener calculate the URL key? How do they work?
本文介绍了URL缩短器如何计算URL密钥?它们如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
URL缩短器如 bit.ly 为每个链接计算一个随机密钥?创建自己的算法我需要知道什么算法?
How do URL shortener's like bit.ly calculate a random key for each link? What algorithm would I need to know to create my own?
推荐答案
到目前为止,我从> http://briancray.com/2009/08/26/free-php-url -shortener-script /
function getShortenedURLFromID ($integer, $base = ALLOWED_CHARS)
{
$length = strlen($base);
while($integer > $length - 1)
{
$out = $base[fmod($integer, $length)] . $out;
$integer = floor( $integer / $length );
}
return $base[$integer] . $out;
}
以及上面提到的Marcel J. 。
这篇关于URL缩短器如何计算URL密钥?它们如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文