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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.