Hey all,
I am learning PHP and I can't find any tutorials or anything for this matter. I am designing a referral system and I want it so after someone registers it emails them the unique code like mydomain.com/referalid?=647364 or something. I know a bit of PHP but this gets to me.
Thanks,
Scott W.
Random Code Generator
Moderator: General Moderators
Re: Random Code Generator
What if you gave sequential codes to each person? First person gets 1, second gets 2, and so on. You can start the numbering anywhere you want: first person gets 294398, second person gets 294399, third gets 294400, etc.
If you want letters too you can do base conversion: 294398 in decimal is 47dfe, for instance.
But that's not actually random: if a person signed up twice they'd see a pattern (albeit a pattern visible everywhere else on the Internet). Does it have to be actually random? Creating unique, "truly" random identifiers can be tricky.
If you want letters too you can do base conversion: 294398 in decimal is 47dfe, for instance.
But that's not actually random: if a person signed up twice they'd see a pattern (albeit a pattern visible everywhere else on the Internet). Does it have to be actually random? Creating unique, "truly" random identifiers can be tricky.
Re: Random Code Generator
Something like this?Example:
makeCode(10);
Code: Select all
function makeCode($length) {
$code = '';
$poss = "ABCDEFGHIJKLMOPQRSTUVWXYZ0123456789abcdefghijklmopqrstuvwxyz";
$i = 0;
while($i < $length) {
$char = substr($poss, mt_rand(0, strlen($poss)-1), 1);
if(!strstr($code, $char)) {
$code .= $char;
$i++;
}
}
return $code;
}makeCode(10);
Re: Random Code Generator
Well, What I am trying to do is make it so that it says "Blank refered you" so it detects who the owner of that ID is.
And that code. It will be different every time?
Thanks,
Scott W.
And that code. It will be different every time?
Thanks,
Scott W.
Re: Random Code Generator
Code: Select all
$id = sha1(time().uniqid(mt_rand(),true));