如何从服务器上的img src属性记录url变量(查询字符串) [英] How to record url variables (query string) from an img src attribute on the server

查看:616
本文介绍了如何从服务器上的img src属性记录url变量(查询字符串)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做类似于Google Analytics(分析)跟踪访问者信息的操作。 Google Analytics(分析)的JavaScript文件会在您的网站上投放1x1图片。当访问者访问您的网站时,他们从Google加载该IMG。 IMG SRC属性包括有关您访问的多个URL变量。例如:

I want to do something similar to what Google Analytics does to track visitor information. Google Analytics' javascript file puts a 1x1 img on your site. When a visitor comes to your site, they load that IMG from Google. The IMG SRC attribute includes a number of URL variables about your visit. For example:

<img src="http://www.google-analytics.com/__utm.gif?utmwv=5.4.6&utms=1&utmn=116154048&utmhn=www.example.com&utmcs=UTF-8&utmsr=1920x1080&utmvp=1439x356...">

当Google收到此图片的请求时,会记录网址变量。

When Google receives the request for this image, they record the URL variables.

我可以创建一个带有所有我需要的URL变量的自定义源的图像。这很容易。但我不能想到如何将其记录在服务器上?我想要它最终在一个数据库,所以我可以运行报告。我的服务器正在运行IIS7和ColdFusion 10.任何想法?

I can create an image with a custom source with all the URL variables I need. That's easy. But I can't think of how to record it on the server? I want it to end up in a database so I can run reports. My server is running IIS7 and ColdFusion 10. Any ideas?

谢谢!

推荐答案

回到ajax之前的日子里,人们习惯于通过 cfcontent 创建一个.cfm页面来提供一个小的透明gif。

Back in the days before ajax, people used to create a .cfm page that served up a small transparent gif via cfcontent.

 <cfcontent type="image/gif" file="c:/path/to/clear.gif">

由于脚本实际上返回了有效的图像,所以它可以用作标记的< img>

Since the script actually returns a valid image, it can be used as the src of an <img> tag.

 <img src="path/to/yourScript.cfm?param1=xxx&param2=yyyy" />

显示图像时,URL变量传递到.cfm脚本,将值插入数据库。只要确保你总是返回一个图像,即使数据库错误由于某种原因。

When the image is displayed, the URL variables are passed to the .cfm script, and you can easily insert the values into a database. Just be sure you always return an image, even if a database error occurred for some reason.

我确定有滑动的选项,但这是如何使用< img> 标记。

I am sure there are slicker options, but that is the basic concept of how it could be achieved using only an <img> tag.

这篇关于如何从服务器上的img src属性记录url变量(查询字符串)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆