Generate short URLs we can directly use a function to generate a unique 5-6-character address, but we also need to do a bit of direct use for static jump, let me introduce to you.
Generate a short URL program
The code is as follows |
Copy Code |
function code62 ($x) { $show = "; while ($x >0) { $s = $x% 62; if ($s >35) { $s =chr ($s +61); }elseif ($s >9&& $s <=35) { $s =chr ($s +55); } $show. = $s; $x =floor ($x/62); } return $show; } function Shorturl ($url) { $url =crc32 ($url); $result =sprintf ("%u", $url); Return code62 ($result); } |
This generates a job like HTT:/Z.CN/ABCFC, but we need to implement a pseudo-static that can be accessed on your Apache or IIS configuration, as follows
The code is as follows |
Copy Code |
How to add http://z.cn/link.php?url=http://www.bKjia.c0m Shrink into Http://z.cn/zHEYrvV |
This place requires a URL rewrite, which, in this case, can be rewritten like this:
The code is as follows |
Copy Code |
Rewriteengine on Rewritebase/ Rewriterule ^/(. *) $ link.php?url=$1[l] |
http://www.bkjia.com/PHPjc/631552.html www.bkjia.com true http://www.bkjia.com/PHPjc/631552.html techarticle generate short URLs we can directly use a function to generate a unique 5-6-character address, but we also need to do a bit of direct use for static jump, below I ...