##### Written by Andrew Gray
##### Do with it what you like
##### I am not responisable for you spelling words wrong
##### contact me at andrew@graymerica.com or visit my web site www.graymerica.com
$incorrectFile = 'incorrectWordList.txt' ;
$correctFile = 'correctWordList.txt' ;
$controlNumber = 5 ; // this is a number between 1-10 that controls how often all the words are spelled correctly.
########### end config
## Start Session to track score
session_start();
if ($_REQUEST['restart'])
{
session_destroy() ;
$_SESSION = '' ;
echo "
Spelling Test
" ;
}
## Set Begining time for tracking total time
if (!isset($_SESSION['startTime']))
{ $_SESSION['startTime'] = date('U') ; }
$currentTime = date('U') ;
$totalTime = $currentTime - $_SESSION['startTime'] ;
### Import files as arrays (one word per line, nothing like)
$incorrectArray = file($incorrectFile) ;
$correctArray = file($correctFile) ;
$allCorrectNumber = rand (0,$controlNumber) ;
if ($allCorrectNumber < 1)
{ $numberCorrect = 4 ;
$numberWrong = 0 ;
$correctKeys = array_rand ($correctArray , $numberCorrect) ;
//$incorrectKey = array_rand ($incorrectArray , $numberWrong) ;
$testArray[0] = $correctArray[$correctKeys[0]] ;
$testArray[1] = $correctArray[$correctKeys[1]] ;
$testArray[2] = $correctArray[$correctKeys[2]] ;
$testArray[3] = $correctArray[$correctKeys[3]] ;
$incorrectWord = "None" ;
$correctChoice = '5' ;
} else
{
$numberCorrect = 3 ;
$numberWrong = 1 ;
$correctKeys = array_rand ($correctArray , $numberCorrect) ;
$incorrectKey = array_rand ($incorrectArray , $numberWrong) ;
$testArray[0] = $correctArray[$correctKeys[0]] ;
$testArray[1] = $correctArray[$correctKeys[1]] ;
$testArray[2] = $correctArray[$correctKeys[2]] ;
$testArray[3] = $incorrectArray[$incorrectKey] ;
shuffle($testArray) ;
$correctChoice = array_search($incorrectArray[$incorrectKey] , $testArray) ;
$incorrectWord = $incorrectArray[$incorrectKey] ;
}
$debugMessage = "
" .
"
All Correct Number: $allCorrectNumber
Number Correct : $numberCorrect
Number Wrong : $numberWrong
Correct Answer : $correctChoice
Incorrect Word : $incorrectWord
" ;
//build test word array
#### Find out if they are correct
if ($_POST) // if the form was submitted
{
if ($_POST['correct'] == $_POST['word'])
{
$message = "You Were Correct" ;
$_SESSION['num_correct'] ++ ;
} else {
$message = "You Were Wrong it was " . $_REQUEST['incorrectWord'] . "" ;
$_SESSION['num_wrong'] ++ ;
}
} // end if POST
?>
Spelling Test
=$message ?>
//$debugMessage ?>
Which one of these is incorrect
Restart Test
Total Time: =floor($totalTime/60) ?> Minutes
Current Score
Number Correct So Far: =$_SESSION['num_correct'] ?>
Number Incorrect So Far: =$_SESSION['num_wrong'] ?>
Problems/Comments -> andrew@graymerica.com
View source code