![]() |
|
[PHP] How to generate unique key of random numbers in PHP - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183) +---- Thread: [PHP] How to generate unique key of random numbers in PHP (/showthread.php?tid=5436024) |
How to generate unique key of random numbers in PHP - Ashish Bisht - Oct 17, 2016 Hi, I am looking for some example code that can help me to generate unique random string of numeric numbers in PHP Applications. I am hoping to resolve this issue with the help of tech developers working around & for this I have researched for many php questions & answers in various forums, but didn't get any satisfactory response. Hoping to get answer here. * - Squito - Oct 17, 2016 Isn't mt_rand good enough or this haven't been suggested to you? http://php.net/manual/en/function.mt-rand.php * - Nibor - Oct 17, 2016 Not sure what exactly you mean, but: PHP Code This is not a secure method, though, for really storing important things etc * - Quad - Oct 17, 2016 http://php.net/manual/en/function.openssl-random-pseudo-bytes.php * - Strider64 - Oct 17, 2016 PHP Code is one way of doing it with OPENSSL. There are true php random number generators libraries out there on the net, just Google and you should find some scripts or how to do it. * - ASDA - Oct 18, 2016 (Oct 17, 2016 11:07 AM)Strider64 Wrote: There are true php random number generators libraries out there on the net, just Google and you should find some scripts or how to do it. lol good luck with that * - Zotima - Oct 18, 2016 PHP Code This usually generates random string of numbers . You can edit the length of numbers too @ $length. If you also want to add special chars and Alphabets just add each alphabet or char to the $charecters variable. For example: PHP Code * - ASDA - Oct 19, 2016 (Oct 18, 2016 12:31 PM)Yani Wrote: You could use random_int() on PHP7 which is quite secure. It uses CryptGenRandom() on Windows and getrandom(2) on Linux, both of which are cryptographically safe. An official PHP5 userland implementation also exists. cryptographically secure != true random though * - F3nrir - Oct 23, 2016 PHP Code I used this function in all my projects and it never disappointed. |