0

Unique id created by php - uniqid() - for example - 63afe4f2903a2 - perfectly suits my needs, although it is not perfectly assured to be unique.

So I need a 13 characters length ID which is made using the same logic as uniqid in php

Is there a way to create it using plain javascript or jquery ?
Thanks.

update

There is no answer on my question here

provance
  • 877
  • 6
  • 10
  • You can use this for generating the uniqueID by javascript or jquery like that Math.random().toString(36).substr(2, 9); – Sajid Ijaz Dec 31 '22 at 08:10
  • _There is no answer on my question here_ Ok, so how many unique IDs you wish to have per request? Are these IDs for div tags or something else? I don't see how none of the answers there answer your question! – nice_dev Dec 31 '22 at 08:10
  • @nice_dev - As I said - I simply want an id - as I got it using php. So - one ID - per request. What for I will use it - that's absolutelly irrelevant here. And you should see very easily that - there is no answer on the given link. – provance Dec 31 '22 at 08:23
  • @provance Ok, so it's one ID per request. _What for I will use it - that's absolutely irrelevant here_ It is been asked because if the ID is handling something critical, it needs to be cryptographically secure and not just unique. Many answers give you a way to get only one unique ID per request. See this fiddle https://onecompiler.com/javascript/3ytgmyew7 – nice_dev Dec 31 '22 at 08:27
  • @nice_dev - As I said - `it perfectly suits my needs, although it is not perfectly assured to be unique`. So - once again - `it perfectly suits my needs, although it is not perfectly assured to be unique`. I hope that's enough now – provance Dec 31 '22 at 08:32
  • @SajidIjaz - your code produce an id of `9` characters. How to get `13` characters as in php,, pls ? – provance Dec 31 '22 at 08:35
  • The "perfectly assured to be unique" is *also* in one click from Google. So I did it for you. – Your Common Sense Dec 31 '22 at 08:36
  • @YourCommonSense - excuse me - can't understand your comment. What about one click on Google and what did you do for me ? – provance Dec 31 '22 at 08:38
  • @provance _although it is not perfectly assured to be unique_ So are you proposing that current time since epoch is not guaranteed to be unique? Your requirement doesn't even need the time to be at micro or nanosecond level. – nice_dev Dec 31 '22 at 08:40
  • @nice_dev - I do not propose anything You should go to php manual. Or simply type `php uniqid` in google. – provance Dec 31 '22 at 08:44
  • @provance Well, we were discussing about javascript solution, weren't we? I even shared the fiddle for the same. Anyways, good luck! – nice_dev Dec 31 '22 at 08:49
  • @nice_dev - thanks, but I don't need a discuss. I need the solution. – provance Dec 31 '22 at 08:53
  • You got shown many solutions, including a live demo, above. If it doesn't help, explain precisely why – ADyson Dec 31 '22 at 11:05

0 Answers0