URL shortening and restoration base62 URL shortening and restoration base62
function enbase62($number,$encode = ''){ $base62 = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; while($number > 0){ $mod = bcmod($number, 62); $encode .= $base62[$mod]; $number = bcp(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;}
2.[SQL] code
Create table 'waoo _ empty url' ('Short _ id' int (12) not null AUTO_INCREMENT COMMENT 'auto-incrementing ID', 'short _ name' varchar (50) default null comment 'Alias ', 'title' varchar (100) default null comment' title', 'link' varchar (800) default null comment' URL link ', 'create _ time' datetime default null comment' creation time', 'uid' int (10) default null comment 'owner ', 'status' tinyint (1) DEFAULT '1' COMMENT '1 valid, 0 block-1 delete', 'Top _ domain' varchar (100) default null comment 'top-level domain name ', 'All _ domain 'varchar (100) not null comment 'domain name full', '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
3.[C/C ++] code
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]
The above is the content for shortening and restoring base62 on the website. For more information, see The PHP Chinese website (www.php1.cn )!