如何半识别用户?

问题描述 投票:0回答:1

如果用户与以前相同,我需要以“高”概率进行检测,我需要为他提供相同的价格。怎么样?

我会检查IP地址和浏览器类型。如果之前收到的内容相同,则进行宾果游戏。

您认为,这是更好的选择吗?我应该使用cookie吗?如果仅按Clear history我不会给他机会以重新标识自己,该怎么办?至少使用其他IP或启动其他浏览器。

您知道我是否可以使用window.location.host获得客户端“ IP”吗?还是其他?

javascript cookies ip-address
1个回答
0
投票

使用cookie。

//Set the previous price
document.cookie = "price=5"

//Get previous price
function getCookie() {
  var name = "price";
  var decodedCookie = decodeURIComponent(document.cookie);
  var ca = decodedCookie.split(';');
  for(var i = 0; i <ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == ' ') {
      c = c.substring(1);
    }
    if (c.indexOf(name) == 0) {
      return c.substring(name.length, c.length);
    }
  }
  return "";
}

有关如何使用cookie的更多信息,请阅读this website

© www.soinside.com 2019 - 2024. All rights reserved.