Reputation: 73
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.how do i prevent this.thanks for your help.
Upvotes: 1
Views: 103
Reputation: 73
I solved the problem by storing the number of questions answered in database and redirecting to that page using header
command.
Upvotes: 0
Reputation: 270775
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
}
Upvotes: 1
Reputation: 6432
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
Upvotes: 0
Reputation: 5481
Just change them to unpredictable names, like kiran.php instead of 1.php, likeyouknowit.php instead of 2.php, etc.
Upvotes: -1
Reputation: 180177
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.
Upvotes: 2