网址缩短与还原, 思路是采用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
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]