外部柜台如何获取独立访客?

发布于 2024-08-29 20:58:03 字数 250 浏览 1 评论 0原文

外部计数器如何通过图像跟踪唯一访客
如果可能的话,我也想获得推荐人。
类似于 img="http://www.somecounterdomain.com/count.php?page=83599"
我正在使用 ASP.NET,c#
我知道用户可以“作弊”,但希望将这种可能性降到最低。
额外的困难是我应该访问外部服务器并且无法在那里实现 C# 代码。
我所能做的只是实现一个反图像或类似的东西。 我尝试使用生成的图像。 感谢您的回答。

how do external counter track unique visitors via image
i'd also like to get Referrer if possible.

something like img="http://www.somecounterdomain.com/count.php?page=83599"

i'm using ASP.NET, c#
i'm aware of a user can "cheat" but would like to make that posibility minimal.
additional difficulty is that i should trach external server and can't implement c# code there.
what i can is only imlement a counter imag or smth like that.
i try to use generated image.
thx for answers.

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

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

发布评论

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

评论(2

十雾 2024-09-05 20:58:03

基本上您需要做的是以下事情。

1- 创建 .ashx 或 .aspx。假设您使用 .aspx 并将其称为 StatServer.aspx,Page_Load 函数将读取查询字符串并将数据写入数据库,您将在步骤 2 中看到查询字符串。如果需要,您可以返回一个图像,该图像可以是呈现。一些粗略的代码看起来像这样。

<代码>

private void Page_Load(object sender, EventArgs e)
{
    WriteQueryStringInformationToDB(Request.QueryString);

Image image = LoadYourImageHere();
using (MemoryStream stream = new MemoryStream())
{
    base.Response.Clear();
    base.Response.ContentType = "image/png";
    image.Save(stream, ImageFormat.Png);
    stream.WriteTo(base.Response.OutputStream);
    base.Response.End();
}

}

2- 这就是魔法,您创建一个小的 .js 文件。在此文件中,您有一个名为 mystats() 的函数,该函数本质上会收集客户端信息,并调用托管您在步骤 1 中创建的页面的 URL。客户端信息(如屏幕大小、引用来源等)都是全部传递查询字符串。该函数中需要包含的一项重要内容是 ID,它指示您正在更新哪个计数器,这样您就可以在多个站点上使用您的计数器。一个非常简单的 .js 可能看起来像这样。 (注意测试等...:))

function mystats(id)
{
    // Base URL including the ID of the counter
    var url="http://yourdomainorservername/statserver.aspx?id="+id;

// Add the referer to the url querystring
url += "&r=" + escape(document.referrer);

// Add screen width + height
url += "&w=" + screen.width + "&h=" + screen.height;

document.write('<img src="'+url+'" border=0 alt="Site statistics">');

}

3-在要应用计数器的网页上,添加一个脚本块,其中包含来自服务器的 .js 文件并从 img 标记调用 mystats 函数,这会导致 js 代码收集信息并发送向服务器发出请求,服务器依次更新数据库并返回要显示的图像流。

Basically what you need to do is the following.

1- Create either a .ashx or .aspx. Assuming you go with .aspx and call it StatServer.aspx, the Page_Load function will read the query string and write the data to a database, you will see the querystring in step 2. If you want, you can return a image which can be rendered. Some rough code will look something like this.

private void Page_Load(object sender, EventArgs e)
{
    WriteQueryStringInformationToDB(Request.QueryString);

Image image = LoadYourImageHere();
using (MemoryStream stream = new MemoryStream())
{
    base.Response.Clear();
    base.Response.ContentType = "image/png";
    image.Save(stream, ImageFormat.Png);
    stream.WriteTo(base.Response.OutputStream);
    base.Response.End();
}

}

2- This is the magic, you create a small .js file. In this file you have a function lets call it mystats() which will essentially gather the client side information and make a call to the URL hosting the page you created in step 1. The client side information like screen size, referer etc. is all passed on the querystring. One important thing to include in the function is an ID which indicates which which counter you are updating, that way you can use your counter on multiple sites. A very simple .js might look something like this. (Note tested etc... :))

function mystats(id)
{
    // Base URL including the ID of the counter
    var url="http://yourdomainorservername/statserver.aspx?id="+id;

// Add the referer to the url querystring
url += "&r=" + escape(document.referrer);

// Add screen width + height
url += "&w=" + screen.width + "&h=" + screen.height;

document.write('<img src="'+url+'" border=0 alt="Site statistics">');

}

3- On the web pages that you want to apply the counter, you add a script block that includes the the .js file from your server and calls the mystats function from an img tag, this causes the js code to collect the info and send a request to your server, which in turn updates the DB and returns the image stream to display.

谜兔 2024-09-05 20:58:03

获取“推荐人”很容易,并且为了计算唯一访问者,您需要设置/检查 cookie。

Getting the 'referer' is easy and for counting unique visitors you'll need to set/check for cookies.

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