doupin5667 2012-09-08 02:52
浏览 25

检查用户是否单击了按钮

What I would like to do is essentially check whether or not a user has clicked a certain link on a page. The idea behind the functionality is that a user can click "Thanks!" on a post created on the website, but they can only submit one "Thanks!" per post.

I have no problem creating a simple click counter for the "Thanks!" button, and save the count to a database using PDO, but I am not sure how I can assign a click to the user who's session is active.Also, posts are constantly being added to the site, so I would need a system which would scale to more posts automatically.

Any guidance is appreciated, thanks!

Note: I know I have not put any example code, but I believe this is simple enough for a good programmer to grasp quickly.

EDIT On further thought, the IP can not be used to distinguish users, as this website will be used by many people on the same IP.

  • 写回答

1条回答 默认 最新

  • doupao2277 2012-09-08 02:57
    关注

    Are the users logged in or anonymous? If they are logged in just save their user id in a session variable and upload it with their vote to a table in your database.

    I do something similar using an Ajax request to a .php page that inserts a row with the session user ID and the vote.

    If they are anonymous you can save their ip but that leads to problems with users who share the same ip address. Another (bad) option is to use cookies but users can obviously just clear their cookies and vote again.

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100