doubo1883 2016-05-10 06:54
浏览 97

检测是否从页面中搜索url而不是在浏览器中复制粘贴的最佳选项

I need to count number of hits of a url being hit from a page but for that I need to detect if url is being hit from page or simply copy pasted.

Can anyone suggest me what to choose among methods:

    1. Using $_SERVER['HTTP_REFERER']
    2. Using sessions
    3. IP matching
  • 写回答

1条回答 默认 最新

  • douyanjing8287 2016-05-10 07:04
    关注

    $_SERVER['HTTP_REFERER'] seems to be the natural choice, however, the php docs at http://php.net/manual/en/reserved.variables.server.php have some intersting stuff to say:

    'HTTP_REFERER' The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

    A more reliable method would be to encode some data dynamically into the URL when it is clicked on the page, like the current UTC datetime. Then server side check if the received timestamp is within 1 or 2 seconds of the current time. If there is a copy and paste, either there will not be a timestamp, or the timestamp will be wrong.

    It is possible that the client will have the wrong time, but unlikely nowadays. To be extra extra sure, you would need to send a timestamp from the server and use this as a base for generating your datetime.


    Following comments:

    agree, timestamps can be subject to network fluctuations. How about encoding some data in a once-time-only cookie (ie expires immediately) with Javascript (which the server can verify). You can't copy and paste a cookie!

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP