I'm lost, I'm frustrated, I am not getting it!
Is there something wrong below with my use of filesize($filename)???
I am trying to generate a replacement random password for people that forget their password. I have tried to strip this down to just the piece that is failing. The code is below.
When I tried to execute it I get the following messages:
$test is false:
Encountered error 8 in /home/consult/public_html/development/Testing/26/test_rand.php5, line 38: Undefined variable: size
Filesize returned:
Fatal error: Uncaught exception 'Exception' with message 'Could not generate new password.' in /home/consult/public_html/development/Testing/26/test_rand.php5:39 Stack trace: #0 {main} thrown in /home/consult/public_html/development/Testing/26/test_rand.php5 on line 39
What is an error 8?
Line 38 is the one that reads:
echo '<p>Filesize returned: ' .$size .' </p>';
<?php
function on_error($num, $str, $file, $line) {
print "Encountered error $num in $file, line $line: $str\n";
}
function get_random_word($min_length, $max_length)
// grab a random word from dictionary between the two lengths
// and return it
{
// generate a random word
$word = '';
// remember to change this path to suit your system
$dictionary = '/usr/share/dict/words'; // the ispell dictionary
$fp = @fopen($dictionary, 'r');
if(!$fp)
echo '<h1>Unable to open dictionary!</h1>';
return false;
$size = filesize($dictionary);
return $size ; //added for testing
}
set_error_handler("on_error");
// get a random dictionary word b/w 6 and 13 chars in length
$test = get_random_word(6, 13);
if($test==false)
echo '<p>$test is false: '.$test .' <\p>';
echo '<p>Filesize returned: ' .$size .' </p>';
throw new Exception('Could not generate new password.');
// add a number between 0 and 999 to it
// to make it a slightly better password
srand ((double) microtime() * 1000000);
$rand_number = rand(0, 999);
$test .= $rand_number;
echo "<p>This is new password: $test </p>";
?>