You are here:

PHP5/PHP Error Messages


Sorry for the lack of clarity. I am saying that I would like to be able to answer the question once, then a cookie is set for that question. So then, after that cookie has been set, I never need to answer the question until the cookie times out. So in this case, after I answer the question on index.php, a cookie is set, and I am redirected to q1.php. So if I ever go back to index.php, then I am redirected back to q1.php, without having to answer the question again. Hope this is a little clearer. Here is the code again

Thanks for the clarification. This is pretty simple. The first step is to write the cookie when someone has answered the question correctly. This is done with the following line:
setcookie('passed_index', '1' ,time()+60*60*24); //This line sets the cookie for 1 year

The other thing you need to do is to check the existence of the cookie at the top of index.php. If it exists, send the user immediately to q1.php

 //Check for the existence of the cookie

That's all there is to it. Of course, in production you would not want to rely on this method, but it does work for your learning scenario.

Full code is available at

Please let me know if you have any other questions.



All Answers

Answers by Expert:

Ask Experts


Kevin Cackler


Any and everything related to PHP4 and PHP5. I specialize in functional, readable, scalable object oriented code, and can answer your troublesome class and object questions.


5 years developing in PHP using flat files and databases (MySQL, Oracle) Lead PHP developer for a very large Texas based web hosting company The coder behind some of the largest pet communities online.


©2016 All rights reserved.