Jump to content

Random Help


timmah1

Recommended Posts

I'm trying to set up a simple little referral code for people that register at our site.

 

I want it to generate as soon as they register, so that it will display upon successul registration.

 

I'm trying to make it a random string of letters and numbers, no more than 8 characters long, but to be honest, I have no idea where to start. The tutorials I did find wasn't really helping.

 

So the questiton I have is, how do you generate a random string of letters and numbers no more than 8 characters long? Is this even possible?

 

Thank you in advance

Link to comment
https://forums.phpfreaks.com/topic/77171-random-help/
Share on other sites

There are many ways to do this, here is one way:

<?php
<?php
$seed_array = array_merge(range('a','z'),range('A','Z'),range(0,9));
$rand_ary = array_rand($seed_array,;
$rand_str = '';
foreach($rand_ary as $rk)
   $rand_str .= $seed_array[$rk];
echo $rand_str."\n";
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/77171-random-help/#findComment-390753
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.