开发者

PHP redirecting to a page problem

I 'm designing a Treasure hunt kind of online quiz.Totally there are 10 files namely 1.php , 2.php..10.php .Only if the player answers the question on the current page he must be redirected to next page ,but in my case if the player modifies the URL he can view the next question.h开发者_如何学JAVAow do i prevent this.thanks for your help.


Store the highest page number the user has accessed in a session variable.

i.e. on 4.php, you'd do $_SESSION['page'] = 4;

On 5.php, you'd check that $_SESSION['page'] is at least 4.

Do note that you'll need to have called session_start() before accessing $_SESSION on all pages that use sessions.


Store a session variable when a question is completed. If the session variable's value is less than the number of the question being accessed, deny access.

session_start();
// just finished question 5, for example
// The user may now access question 6
$_SESSION['question'] = 6;


// User attempts to access a question:
// Suppose $current_question is 7
if ($_SESSION['question'] < $current_question) {
  // deny
}
else {
  // display the question
}


You could pass a random id along with the client when you redirect him to the next page and then verify that random id when he arrives at the next page. I guess this would be the same thing as using a php session. http://us.php.net/manual/en/book.session.php


I solved the problem by storing the number of questions answered in database and redirecting to that page using header command.


Just change them to unpredictable names, like kiran.php instead of 1.php, likeyouknowit.php instead of 2.php, etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜