<!DOCTYPE html>
<html>
<head>
<title>Browse Directories</title>
<meta charset="utf-8">
</head>
<body>
<p>從字典中獲取一個隨機單詞,以生成新的密碼</p>
<?php
function get_random_word($min_length, $max_length)
{
$word = '';
$dictionary = '字典路徑';
$fp = @fopen($dictionary, 'r');
if(!$fp)
{
echo '不能打開文件';
return false;
}
$size = filesize($dictionary);
$rand_location = rand(0, $size);
fseek($fp, $rand_location);
//獲取一個長度介於$min_length和$max_length之間,並且不包含'
while((strlen($word) < $min_length) || (strlen($word) > $max_length) || (strstr($word, "'")))
{
if(feof($fp))//如果查找單詞的文件尾,就從頭開始
{
fseek($fp, 0);
}
$word = fgets($fp, 80);//因爲第一次可能獲取到單詞的一部分,所以使用兩次fgets
$word = fgets($fp, 80);
}
$word = trim($word);
return $word;
}
echo get_random_word(7, 16);
?>
</body>
</html>
詞典上傳路徑https://sourceforge.net/projects/wordlist/?source=typ_redirect