假设我有一个带有问题的php哈希,作为子句的关键,将答案作为其正确性值的关键:
$questions = array(
//1
"What?" => array(
"Answer A" => "false",
"Answer B" => "false",
"Answer C" => "true",
"Answer D" => "false",
"expl" => "**C is the correct answer."//also holds the explanations of these questions
),
"When?" => array(
"Answer A" => "false",
"Answer B" => "false",
"Answer C" => "false",
"Answer D" => "true",
"expl" => "**D is the correct answer, because..."
),
...
...
...
//12
"How?" => array(
"Answer A" => "true",
"Answer B" => "false",
"Answer C" => "false",
"Answer D" => "false",
"expl" => "**A is the correct answer."
)
);
我想根据用户之前使用此功能的信息输出这些问题的子序列:
function checkpoint($type){
global $questions;
//defined the subsequences for each type
$sub1 = array(1, 3, 4, 9, 5, 6, 10, 8, 11, 12);
$sub2 = array(1, 3, 4, 9, 5, 6, 10, 8, 11, 12);
$sub3 = array(1, 2, 3, 4, 12, 6, 10, 7, 8);
switch($type){
case 1: $questionpath = $sub1; break;
case 2: $questionpath = $sub2; break;
default: $questionpath = $sub3;
}
$q_strings = array_keys($questions);
$letters = range('A', 'Z');
//output
for($i = 0; $i < count($questionpath); $i++){
$qnum = $questionpath[$i] - 1; //the index of the question
$question = array_keys($questions)[$qnum];
$answers = array_keys($questions[$question]);
echo '<table><tr><td>'.($i+1).'</td>
<td>'.$question.'</td>
</tr></table>';
for($j = 0; $j < count($answers); $j++){
if($answers[$j] != "expl")
echo '<input type="radio" name="q'.($i+1).'" id="q'.($i+1).'a'.($j+1).'" onchange="showAnswer($(\'#correct'.($i+1).'\'),'.$questions[$question][$answers[$j]].');"><label for="q'.($i+1).'a'.($j+1).'">'.range('A', 'Z')[$j].'. '.$answers[$j].'</label></br />';
}
echo '<span id="correct'.($i+1).'" class="correct"><i>'.$questions[$question]['expl'].'</i></span>
<span class="correct"><i>'.$questions[$question]['expl'].'</i></span>
</div>
<br />';
}
}
在“.inc”文件中使用此功能已在我的本地服务器上运行,但在实时服务器上使用会导致403错误。
但是,更改代码以便不会出现多维访问:
$q_arr = $questions[$question];
并将访问次数更改为:
$questions[$question][$answers[$j]]
类似于:
$q_arr[$ans]
修复了这403个错误。那么,服务器是否可以通过访问多维数组的代码来提供403错误?