SharkBait Posted May 26, 2006 Share Posted May 26, 2006 Ok, lets see if I can explain this better....What I am looking to do is figure out a way to create a random code made up of alphanumeric characters.The reason: So customers can enter this unique, generate code into a website for something special ;)I would then have to insert the randomly generated codes into a database so that I can check to see if its been used or not used etc.The code should less than 10 characters.I am just unsure how I should tackle this. I thought of a hash or sort, but can I make a hash for 10 characters or less?Perhaps some sort of Algorithm so that when they enter their code I can check to see if it is valid, and then I can check to see if its already used (as in already in the database)Kind of like how credticard seeds work.Any thoughts/advice is grealy appreicated :) Link to comment https://forums.phpfreaks.com/topic/10526-generating-a-bunch-of-random-codenumbers/ Share on other sites More sharing options...
.josh Posted May 26, 2006 Share Posted May 26, 2006 umm... you mean like the same thing a random password generator/reset script does, like this:aX87b92h3? Link to comment https://forums.phpfreaks.com/topic/10526-generating-a-bunch-of-random-codenumbers/#findComment-39258 Share on other sites More sharing options...
SharkBait Posted May 26, 2006 Author Share Posted May 26, 2006 Yea I guess something like that. Link to comment https://forums.phpfreaks.com/topic/10526-generating-a-bunch-of-random-codenumbers/#findComment-39273 Share on other sites More sharing options...
nogray Posted May 26, 2006 Share Posted May 26, 2006 I made a small function that will generate random passwords a while back. You can change the $rand string to any characters you want to use.[code]function createPass(){ $num_letters = 10; $rand = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; for($i=0; $i<$num_letters; $i++){ $pass .= substr($rand, rand(0, strlen($rand)-1), 1); } return $pass;}[/code]hope this helps ya Link to comment https://forums.phpfreaks.com/topic/10526-generating-a-bunch-of-random-codenumbers/#findComment-39298 Share on other sites More sharing options...
ryanlwh Posted May 26, 2006 Share Posted May 26, 2006 there are a lot of ways to do it. you can hash the current timestamp and then substring the first 10 characters.also, the above example can be simplified with str_shuffle;[code]$rand = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";$pass = substr(str_shuffle($rand),0,10);[/code] Link to comment https://forums.phpfreaks.com/topic/10526-generating-a-bunch-of-random-codenumbers/#findComment-39315 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.