search
Homephp教程PHP源码网址缩短与还原base62

网址缩短与还原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]代码 

CREATE TABLE `waoo_shorturl` (
  `short_id` int(12) NOT NULL AUTO_INCREMENT COMMENT &#39;自增id&#39;,
  `short_name` varchar(50) DEFAULT NULL COMMENT &#39;别名&#39;,
  `title` varchar(100) DEFAULT NULL COMMENT &#39;标题&#39;,
  `link` varchar(800) DEFAULT NULL COMMENT &#39;网址链接&#39;,
  `create_time` datetime DEFAULT NULL COMMENT &#39;创建时间&#39;,
  `uid` int(10) DEFAULT NULL COMMENT &#39;拥有者&#39;,
  `status` tinyint(1) DEFAULT &#39;1&#39; COMMENT &#39;1有效, 0封禁 -1删除&#39;,
  `top_domain` varchar(100) DEFAULT NULL COMMENT &#39;顶级域名&#39;,
  `all_domain` varchar(100) NOT NULL COMMENT &#39;域名全文&#39;,
  `create_ip` varchar(15) NOT NULL COMMENT &#39;ip&#39;,
  PRIMARY KEY (`short_id`),
  UNIQUE KEY `short_name` (`short_name`)
) ENGINE=MyISAM AUTO_INCREMENT=12 DEFAULT CHARSET=utf8

3.[C/C++]代码 

<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>

           

 以上就是网址缩短与还原base62的内容,更多相关内容请关注PHP中文网(www.php.cn)!

       

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.