1

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.

1
  • You could use sessions to store what step the player is at and then just have one question.php page that shows them the next question based on their progress. Commented Aug 20, 2011 at 18:10

5 Answers 5

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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
}

1 Comment

,Thanks for your help. I solved the problem by storing the number of questions answered in database and redirecting to that page using "header" command.
0

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

Comments

0

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

1 Comment

In each page check whether (number of questions answered=current question -1) .if true display the question else redirect to the page where the user actually should be.
-1

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

4 Comments

Until someone writes them down and posts them to a forum somewhere.
This does not solve the customer's question at all in the long term
@Michael: and it's different than them writing down the answers? I personally like that approach: so if I have to quit mid-way, I can still come back to it later, instead of doing it all again (unless the OP wants it). Marc: the OP says he has only 10 pages, so I opt for an easy solution, instead of a scalable one.
@Ahn if they write down the answers, they still at least need to click through each page to get to the next.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.