Dave Smith - 2017-01-11 16:37:48 -
In reply to message 1 from Jon Lennryd
I had not considered making the secret path not such a secret and informing the user what to do next. The authorization test is just returning true or false, so we need to make a couple of changes to make it work.
1) We need to make the userPath public so that we can access where they are in the path. In secretpath.class.php, change...
private $userPath;
TO...
public $userPath;
2) Using the code from the article, replace this block...
if( $secpth->validatePath( false ) === true ) {
$userNotice = 'Congratulations, you completed the path';
$secpth = new secretPath( 'link', '*', 4,9);
} elseif( !empty($_SESSION['secpth']) ){
$userNotice = ( $secpth->testUserPath() ) ? 'You are on the right track' : 'Wrong track, try again';
}
WITH...
$noticeArray = array(
'',
'Click on Link 1',
'Click on Link 2',
'Click on Link 3',
'Click on Link 4',
'Click on Link 5',
'Click on Link 6',
'Click on Link 7',
'Click on Link 8',
'Click on Link 9',
);
$path = $secpth->getSecPath();
if( $secpth->validatePath(false) === true ){
$userNotice = 'Congratulations, you completed the path. ';
$secpth = new secretPath('link','*',4,9);
$userNotice .= $noticeArray[$path[0]];
}elseif( !empty($_SESSION['secpth']) ){
$userCount = ( !empty($secpth->userPath) ) ? count($secpth->userPath) : 0;
$userNotice = ( $secpth->testUserPath() ) ? 'You are on the right track. '.$noticeArray[$path[$userCount]] : 'Wrong track, try again. '.$noticeArray[$path[0]];
}else{
$userNotice = $noticeArray[$path[0]];
}
We have created a $noticeArray which will inform the user which link to click and used the users current successful clicks to display that message for the next correct link.
Dave