Generate a short URL program
The code is as follows: |
Copy code |
<? Php 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 compute url ($ url ){ $ Url = crc32 ($ url ); $ Result = sprintf ("% u", $ url ); Return code62 ($ result ); } |
In this way, the generated job is like htt:/z.cn/abcfc, but to achieve access, we need to configure a pseudo static file in your apache or iis, as shown below:
The code is as follows: |
Copy code |
How to set Http://z.cn/link.php? Url = http://www.111cn.net Scale down Http://z.cn/zHEYrvV |
In this case, url rewriting is required. In this example, you can rewrite it as follows:
The code is as follows: |
Copy code |
RewriteEngine On RewriteBase/ RewriteRule ^/(. *) $ link. php? Url = $1 [L] |