Jump to content

Recommended Posts

Ok, so I'm attempting to work on a script that will generate random codes and I also want to be able to change the multiplier with a form. Here is what I have so far:

 

<code>

 

 

<?php

$chars = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // Alpha numberic character

$chars .= "123456789";

$chars .= "123456789";

$chars .= "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

$chars .= "123456789";

$chars .= "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

$chars .= "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

$chars .= "123456789";

$chars .= "123456789";

$chars = str_shuffle($chars);

$chars = substr($chars, 0, 15);

 

/** This is the part I'm not sure how to do because

it generates the same codes 5 times in a row and I want

it to generate different codes on each line or maybe do a form that

I can change the multiplier number to generate more

*/

 

$input = $chars;

$multiplier = 5;

$separator = "<br>\n";

print implode($separator, array_fill(0, $multiplier, $input));

print "<br>\n";

 

?>

</code>

 

Sorry I'm a n00b and trying to learn more =)

Link to comment
https://forums.phpfreaks.com/topic/270443-random-code-generator/
Share on other sites

<?php

$letters    = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // Alpha characters
$numbers    = "123456789"; //Numeric characters
$characters = str_repeat($letters, 4) . str_repeat($numbers, 9);

$multiplier = 5;
$length = 15;
$separator = "<br>\n";

$codes = array();
for($i=0; $i<$multiplier; $i++)
{
   $rand_chars = str_shuffle($characters);
   $codes[] = substr($rand_chars, 0, $length);
}

print implode($separator, $codes);
print "<br>\n";

?>

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.