Alternative to Hashing for URL Shortening
Seeking a PHP solution to create concise hashes like those employed by URL shortening services such as TinyURL? While hashing may come to mind, this response unveils a different approach.
TinyURL does not rely on hashing but rather utilizes Base 36 integers (or even Base 62 including uppercase and lowercase letters) to identify the target record. Convert Base 36 strings to integers with intval($str, 36) and vice versa with base_convert($val, 10, 36).
This alternative offers several advantages over hashing. It eliminates collision possibilities and allows for efficient checking of URL existence with the retrieval of the corresponding ID in Base 36. Instead of redirecting to "/url/1234," the shortened URL becomes "/url/ax," providing increased functionality.
By leveraging alternative bases instead of hashing, this method offers speed, collision resistance, and enhanced functionality for URL shortening applications in PHP.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3