我正在创建一个在线测验。我正在从数据库中获取随机问题并将其显示给用户。通过刷新页面将发出另一个请求,用户将得到一组不同的问题。如何防止
问问题
58 次
1 回答
1
根据Nemoden 的评论:
<?php
// start session
session_start();
// if questions were not fetched for this session yet...
if( !isset( $_SESSION[ 'questions' ] ) )
{
// fetch questions and put in $_SESSION[ 'questions' ]
$_SESSION[ 'questions' ] = fetchRandomQuestionsFromDatabase();
}
// loop through $_SESSION[ 'questions' ] and do something with each question
foreach( $_SESSION[ 'questions' ] as $question )
{
// print question, or something
}
于 2012-11-16T10:18:03.480 回答