简体   繁体   English

Node.js中具有唯一随机令牌的URL

[英]URLs with unique random tokens in Node.js

For my project I'd like users to be redirected to their own unique url when they arrive to the website. 对于我的项目,我希望用户在到达网站时将其重定向到他们自己的唯一URL。

eg user goes to mydomain.com they get redirected to mydomain.com/xyz123 例如,用户转到mydomain.com,他们将重定向到mydomain.com/xyz123

I have this working. 我有这个工作。 However I have 2 questions: 但是我有两个问题:

  1. How many characters should the random token ideally have? 理想情况下,随机令牌应具有几个字符 (is there a formula for calculating total amount of tokens possible?) (是否存在用于计算令牌总数的公式?)
  2. How do I stop bots constantly hitting the site and taking up these tokens? 如何阻止僵尸程序不断访问该站点并占用这些令牌?

Thanks for your help. 谢谢你的帮助。

  1. This depends on how many visitors (users?) you expect to have. 这取决于您期望有多少个访客(用户?)。 If you stick to just Latin letters and numerals, and are case sensitive, that gives you 62 unique possibilities per character (26 * 2 + 10), so 62^n where n is the number of characters in your URL. 如果仅使用拉丁字母和数字并且区分大小写,则每个字符有62种独特的可能性(26 * 2 + 10),因此62 ^ n其中n是URL中的字符数。 62^5 is just over 916 million which should last a while. 62 ^ 5刚刚超过9.16亿,应该持续一段时间。
  2. This is much harder. 这要困难得多。 Basically you would need to look at the user agent string and determine whether the visitor was a bot. 基本上,您需要查看用户代理字符串,并确定访问者是否是机器人。 If they are, don't bother redirecting them. 如果它们是,请不要麻烦重定向它们。 See: How to recognize bots with php? 请参阅: 如何使用php识别机器人?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM