PHP URL Shortening Algorithm

后端 未结 7 884
说谎
说谎 2020-12-28 09:22

Could anyone recommend a preferred algorithm to use for URL shortening? I\'m coding using PHP. Initially I thought about writing something that would start at a character su

7条回答
  •  时光取名叫无心
    2020-12-28 09:32

    I adopted a "light" solution. On user request I generate a unique identifier (checking for conflicts in db) with this python snipplet:

    url_hash = base64.b64encode(os.urandom(int(math.ceil(0.75*7))))[:6]
    

    and store it in db.

提交回复
热议问题