How to record url variables (query string) from an img src attribute on the server

▼魔方 西西 提交于 2019-12-13 04:34:30

问题


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...">

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

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?

Thanks!


回答1:


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">

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" />

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.

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



来源:https://stackoverflow.com/questions/21052429/how-to-record-url-variables-query-string-from-an-img-src-attribute-on-the-serv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!