网址缩短与还原base62

2019PHP高薪工程师学习路线图....>>>

网址缩短与还原, 思路是采用htaccess 转发网址到指定controller , 采用mysql 数据库存储数据  , 示例:  http://2vm.win/  

缩短效果:  http://2vm.win/s/shorturl              http://2vm.win/d/d

二维码:  http://2vm.win/s/shorturl/qr            http://2vm.win/d/d/qr
function enbase62($number,$encode = ''){
    $base62 = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    while($number > 0){
        $mod = bcmod($number, 62);
        $encode .= $base62[$mod];
        $number = bcdiv(bcsub($number, $mod), 62);
    }
    return strrev($encode);
}

function debase62($encode, $number = 0){
    $base62 = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $length = strlen($encode);
    $baselist = array_flip(str_split($base62));
    for($i = 0; $i < $length; $i++){
        $number = bcadd($number, bcmul($baselist[$encode[$i]], bcpow(62, $length - $i - 1)));
    }
    return $number;
}
CREATE TABLE `waoo_shorturl` (
  `short_id` int(12) NOT NULL AUTO_INCREMENT COMMENT '自增id',
  `short_name` varchar(50) DEFAULT NULL COMMENT '别名',
  `title` varchar(100) DEFAULT NULL COMMENT '标题',
  `link` varchar(800) DEFAULT NULL COMMENT '网址链接',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `uid` int(10) DEFAULT NULL COMMENT '拥有者',
  `status` tinyint(1) DEFAULT '1' COMMENT '1有效, 0封禁 -1删除',
  `top_domain` varchar(100) DEFAULT NULL COMMENT '顶级域名',
  `all_domain` varchar(100) NOT NULL COMMENT '域名全文',
  `create_ip` varchar(15) NOT NULL COMMENT 'ip',
  PRIMARY KEY (`short_id`),
  UNIQUE KEY `short_name` (`short_name`)
) ENGINE=MyISAM AUTO_INCREMENT=12 DEFAULT CHARSET=utf8
<IfModule mod_rewrite.c>
  Options +FollowSymlinks
  RewriteEngine On

  RewriteRule /d/(?!index)(.*) /d/index/?short_id=$1 [L,NC]
  RewriteRule /s/(?!index)(.*) /s/index/?short_name=$1 [L,NC]
  
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>