Creating your own TinyURL

前端 未结 13 2147

I have just found this great tutorial as it is something that I need.

However, after having a look, it seems that this might be inefficient. The way it works is, fir

13条回答
  •  臣服心动
    2020-12-13 12:13

    Couldn't you just trim the hash to the length you wish?

    $tinyURL = substr(md5($longURL . time()),0,4);
    

    Granted, this may not provide as much pseudo randomness as using the entire string length. But, if you hash the long URL concatenated with the time(), wouldn't this be sufficient? Thoughts on using this method? Thanks!

提交回复
热议问题