Generating name & password
Hi,
Just wondering if anyone could help me out with this bit of code. The code is generating 10 random upper and lower case letters which I am using as a username and password.
Basically, I have the following code:
Code:
<?php
/*
* Generate Username and Password.
*/
$password ="";
$username="";
for ($i = 0; $i < 10; $i++)
{
$r = rand(0,1);
$c = ($r==0)? rand(65,90) : rand(97,122);
$password .= chr($c);
}
for ($i = 0; $i < 10; $i++)
{
$r = rand(0,1);
$c = ($r==0)? rand(65,90) : rand(97,122);
$username .= chr($c);
}
?>
The username and password is then echoed in a table for the user. I have a little problem with it though. Each time the page is refreshed, it changes. I completely expected that to happen, but I want it to generate these two lines only ONCE.
I thought if I copied $username and $password variables into another set of variables and print those to the user instead, it may work. However, it doesn't work and it still changes on page refresh because the whole thing is being executed again.
Anyone know how I might go about doing it?
Thanks. :)