开发者

How can i check if a link has been clicked already?

I'm working on a PHP Jeopardy game, I need a way to find out how to check if a link to a question has been clicked and hide it once it has.

I also need a way to refresh the gameboard to show all question links again.

Does anybody know how i can do this?

Edit:

The se开发者_如何转开发tup of my game is quite simple. Users do not have to register.

You are presented with a jeopardy board from which the questions are taken from a mysql database the questions and answers are stored using get (i didn't want to have to make multiple sql requests). When you click on the question category (e.g. Category 1, $100) it will bring you to the page that will display the question on this page is a link back to the board and a link to the answer. On the answer page there is only the answer and a link back to the board page. (makes sense to me let me know if it doesn't)


You can get a visited link with CSS. This is done through the so called pseudo-classes in CSS (more info on pseudo-classess here)

So for CSS you can do something like:

a.jeopardyquestion:visited {display: none;}

And then if you want to show all the questions just do:

$("a.jeopardyquestion").toggle(true); // to show them

Big edit: There is no reliable way to do this with just CSS and JS with pseudoclasses. Seems that they are going to drop the support for the :visited property altogether from the browsers. Currently Chrome completely ignores styles for :visited links, except the color property. Even then, there is no way to sniff the color, because chrome lies and returns the color of the link, without applying the :visited rule. Firefox still supports the :visited pseudoclass, but it seems that this will too be dropped soon.

So if you want to keep track of the links the user visited, you must use some combination of either javascript+cookies to track the visited links, e.g.:

  1. User visits the "dashboard"
  2. Clicks a link
  3. The question ID is stored(appended) to a cookie (for example: "5,12,22,45");
  4. The user returns to the page
  5. Read the cookie and show only the links that are not in the cookie.

Or you can use some AJAX to give the server information about the visited questions. That way you can achieve even more security (and cheat-prevention) by sending to the user just the questions he must see and do all the checks on the server-side, for example:

  1. User chooses a question
  2. Either AJAX call before navigating, or just put the opened question in the session when the question page loads
  3. The user returns to the question page
  4. While generating the question page, read the session and see which questions the user answered, and do not display them.


If your clients have to register, you can store their clicks in database, if not, you can store the clicks in session or cookie. But it depends on your application.


The simple solution would probably be to give each link a unique id and use javascript to hide it client side. You can use javascript to make them visible again.

EDIT: Use a session to associate with each user. They don't need to register for this.

Use ajax for clicks on the question update the screen with the question. This will prevent your users from snooping in the source to get the answers. Associate which questions have been seen with your session cookie somewhere and refuse to send the same question.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜