Home > Article > Backend Development > Ideas and implementation of generating short URLs in PHP
implemented http://t.cn/link. php?url=zHEYrvV is converted to http://t.cn/zHEYrvV, which is much shortened. So how to find the URL http://bbs.it-home.org/sitejs-17300-1.html through zHEYrvV? And jump to this URL? An encryption-like algorithm is used here. Through the algorithm, all long URLs are shortened into a corresponding 5-6-digit and unique string, and this correspondence is stored in the database. Combined with this example, we go to the database to find the corresponding URL according to the incoming parameter zHEYrvV. If we find it, we will jump to it with the header. Share a PHP short URL generation code (here, the long URL is generated to a length of 5-6 characters and needs to be unique):
For example echo shorturl('http://bbs.it-home.org/'); A unique corresponding code will be generated. For url rewriting methods, please refer to the article: php pseudo-static url rewriting simple example How to write php pseudo-static (url rewriting) How to quickly rewrite url in php5.3 or above version |