Hi, very new to the php game and I'm currently playing around with this code (written by Snowknight) that generates random text:
<?php
//Copyright Snowknight
function NewPassword () {
$Text = "This is merely the text that will be encrypted, change it if needed";
$Length = 10; #How long the password will be
$Text = md5($Text);
srand ((double) microtime() * 1000000);
$StringLength = strlen($Text);
$Beginpoint = rand(0,($StringLength-$Length-1));
$EncPassword = substr($Text, $Beginpoint, $Length);
print ("$EncPassword");
}
?>
<html>
<head><title>Password Generator</title>
</head>
<body bgcolor="#FFFFFF">
<?php
NewPassword();
?>
</body>
</html>
I want to generate more than one unique NewPassword and the most that I've done is simply echo the NewPassword script -
<?php
NewPassword();
echo NewPassword();
?>
I'd like to repeat this script 10-100 times, or whatever I choose (I'd also like to add a <br /> properly, as all of my attempts are failing). Is echo the right choice, should I be looping it using 'while' or 'for'? The goal is to learn how to loop and stop after a set number of times. Thanks.
Looping text generator code
Moderator: General Moderators
Use:
that'll run the function 100 times. Change the 100 to your number of choice.
Hope that works for you...
-Nay
Code: Select all
<?
for ($i=0;$i<[b]100[/b];$i++) {
NewPassword();
}
?>Hope that works for you...
-Nay
Or...
Sidenote:
Nay's example works, But added misc chars in this line:
because I think he tried to make the 100 bolded.
Code: Select all
<?php
function NewPassword ($Times) {
$Text = "The text...";
$Text = md5($Text);
$Length = 10;
for ($i=0;$i<$Times;$i++) {
srand ((double) microtime() * 65546);
$StringLength = strlen($Text);
$Beginpoint = rand(0,($StringLength-$Length-1));
$EncPassword = substr($Text, $Beginpoint, $Length);
echo $EncPassword . '<br />';
}
}
// Call the function, and add how many times you want one generated.
NewPassword(10);
?>Nay's example works, But added misc chars in this line:
Code: Select all
for ($i=0;$i<їb:4afb9d1442]100ї/b:4afb9d1442];$i++) {Code: Select all
for ($i=0;$i<100;$i++) {