Short unique id in php

前端 未结 16 999
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 17:34

I want to create a unique id but uniqid() is giving something like \'492607b0ee414\'. What i would like is something similar to what tinyurl gives:

16条回答
  •  一个人的身影
    2020-11-29 18:02

    I came up with what I think is a pretty cool solution doing this without a uniqueness check. I thought I'd share for any future visitors.

    A counter is a really easy way to guarantee uniqueness or if you're using a database a primary key also guarantees uniqueness. The problem is it looks bad and and might be vulnerable. So I took the sequence and jumbled it up with a cipher. Since the cipher can be reversed, I know each id is unique while still appearing random.

    It's python not php, but I uploaded the code here: https://github.com/adecker89/Tiny-Unique-Identifiers

提交回复
热议问题