如何确认用户拥有像 Google Analytics 这样的网站?

发布于 2024-10-07 04:46:24 字数 151 浏览 4 评论 0原文

我想为用户实现一个脚本,以确认某个网站归他们所有(或者至少他们可以控制该网站),就像 Google Analytics 的做法一样。这样做最安全的方法是什么?我知道 Google Analytics 要求您将脚本上传到网站的根目录,但是还有其他方法吗?另外,谷歌分析是如何实现这一目标的?

I want to implement a script for users to confirm that a website is owned by them (or at least they have control over it) like how Google Analytics does it. What is the most secure way of doing this? I know Google Analytics require you to upload a script to your site's root directory, but are there other ways of doing it? Also, how does Google Analytics accomplish this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

国产ˉ祖宗 2024-10-14 04:46:24

Google Analytics 不要求您将任何内容上传到根目录,也不要求您拥有自己的域。 (它确实提供了一项可选的验证服务,它会尝试告诉您是否已将 Google Analytics(分析)代码段添加到您的网页中。)

Google Analytics(分析)接受对特定帐户的任何点击,但不接受验证谁拥有哪个网站。 (如果有人获取您的 Google Analytics(分析)代码段(包括帐号)并在自己的网站上使用它,这很少会导致问题,但这些数据很容易被过滤掉。)

一些工具,例如 Google 网站管理员工具,要求您证明您拥有一个网站。

验证域所有权的两种最常见的方法是:

  1. 系统会要求您将具有特定名称的文件上传到您的根目录,并对其进行检查。
  2. 系统会要求您创建具有特定值的 DNS 记录,通常是 CNAME 记录。

在这两种情况下,服务都会检查是否已进行更改,通常允许用户启动验证检查(在完成步骤后)。据推测,可以通过使用类似 curl 的方式来查看文件是否存在,和/或通过 ping 域的 DNS 来查看记录是否存在。

编辑:

所以,第一个的常见方法是指示他们创建一个具有特定名称和特定内容的文件。因此,假设您告诉他们创建一个名为 bz239239239.html 的页面,并告诉他们该文件应包含文本 checkbz239239239

然后,为了验证他们是否遵循了您的指示,(PHP 示例)

$contents = @file_get_contents('http://example.com/bz239239239.html');
if(strstr($contents, 'checkbz239239239'))
{
 return true; //this condition means that the page exists and it contains the text that it should.
}

我不是 DNS 专家,但我的理解是 DNS 被认为与网站本身一样安全。即,您可以假设它是安全的,但理论上它有可能被黑客攻击,但到那时,整个网站本身就会受到损害,这是他们的问题,而不是您的问题。

Google Analytics does not require that you upload anything to your root directory, nor does it require that you own your domain. (It does provide an optional validation service, where it will try to tell you if you've added the Google Analytics snippet to your pages.)

Google Analytics accepts any hits to a particular account, and doesn't validate who owns what site. (This can rarely cause problems if someone grabs your Google Analytics snippet, account number included, and uses it on their own site, but that data can easily be filtered out.)

Some tools, like Google Webmaster Tools, require that you certify that you own a website.

The two most common ways of certifying ownership of a domain are:

  1. You are asked to upload a file with a particular name to your root directory, and it checks it.
  2. You are asked to create a DNS record with particular values, usually a CNAME record.

In both cases, the services checks if the change has been made, usually allowing the user to initiate the validation check (after they've completed the steps). Presumably, by using something like curl to see if the file exists, and/pr by pinging the domain's DNS to see if the record exists.

EDIT:

So, the common method of doing number one is to instruct them to create a file with a particular name and particular contents. So, let's say you tell them to create a page called bz239239239.html, and tell them that the file should contain the text checkbz239239239.

Then, to validate that they followed your directions, (PHP sample)

$contents = @file_get_contents('http://example.com/bz239239239.html');
if(strstr($contents, 'checkbz239239239'))
{
 return true; //this condition means that the page exists and it contains the text that it should.
}

I'm not an expert in DNS, but my understanding is that DNS is considered to be as secure as the site itself. ie, you can assume its secure, but it is in theory possible for it to be hacked, but at that point, the entire site itself is compromised, which is their problem, not yours.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文