最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Is it possible to detect a visitor's browsing history using JavaScript or PHP? - Stack Overflow

programmeradmin0浏览0评论

I want to check if my site's visitors have visited another particular site before coming to mine.

I know how to use JS and PHP to check to see (via referrer info) if the user has just come from that site to mine, but I would like to be able to detect if they have visited this site at any time before (not just immediately before coming to my site). Can this information be detected?

I want to check if my site's visitors have visited another particular site before coming to mine.

I know how to use JS and PHP to check to see (via referrer info) if the user has just come from that site to mine, but I would like to be able to detect if they have visited this site at any time before (not just immediately before coming to my site). Can this information be detected?

Share Improve this question asked Jul 19, 2010 at 1:17 LilacsLilacs 1431 silver badge4 bronze badges
Add a comment  | 

5 Answers 5

Reset to default 16

Unfortunately, this is possible this is possible.

You can apply a CSS rule to a:visited that has a background image for a PHP script.

You used to be able to do it (with JavaScript and the CSS psuedo class :visited), but browsers have fixed that exploit.

Yes of course! simply ask the other site if you can pop a script on their site which passes your system the information needed ;)

There is a hack that allows you to do this, but you won't be able to do it deterministically for all browsers as they may try to hide this information. Also, you will not be able to determine that on the server side, but only through the client side. The idea is to manipulate the stylesheet of visited links as @SLaks already states while I was typing :).

Let's say if you were interested in finding out if a site user has visited google.com. Then insert a link to google into your page, and set a unique style for visited links, the effects of which are known beforehand. In the case below, visited links will be colored with #012345.

<style>
a:visited {
    color: #012345;
}
</style>

<a href="http://www.google.com"></a>
<a href="http://www.amazon.com"></a>

Then go through each link you have inserted into the page, and get it's color. If it's #012345 for the above example, then the user has visited that link. You can't actually access their history to know which sites they visited, however. It's more of a polling process.

If you don't mind probabilistic answers, you can time how long it takes to do DNS lookups on the hosts in question. If the DNS answer comes back very quickly, then they might have done a DNS request for that host recently. If the DNS answer comes back slower, then they might not have done a DNS request for that host recently. Of course, my cable modem is going to be giving much faster results than CDMA or GSM phones, so it might only be useful if you're comparing several sites on a single machine.

Edit, in response to Alex's point about ISP DNS caching:

For example: With a local DNS cache, my initial queries for domains took an average 1.6 seconds. (I assume because the cache was very cold, and needed to find .com, .co.uk, and .co.jp nameservers.) Hot-cache queries averaged 0.006 seconds. My DNS cache is a recursive resolver, so it does not use my ISP's caching resolvers.

Without using my local DNS cache and using the DNS cache on my cute router, my initial queries averaged .910 seconds and hot-cache queries averaged .514 seconds. I don't know if the .4 seconds saved are from my router's DNS caching or my ISP's caching. But even .4 seconds should be visible in Javascript.

There is enough data to make some guesses: if the time for the first and second attempts to resolve the domain name are similar, you can assume the cache was hot and the address had been used recently. (Perhaps hot at the ISP level, but this was marketed as a probabilistic method in any event. :) If the times are dissimilar, you can assume the cache was cold.

When using my ISP's DNS, I guessed nine 'hot' domains and nine 'cold' domains, and the average lookup time for hot was .226 seconds, and the average lookup time for cold was .308 seconds. The difference of .082 seconds might not be large enough to notice in javascript, and it definitely pales in comparison to the differences between known-hot and known-cold lookups using a local cache or my cute little router for DNS.

Of course 'hot' and 'cold' are relative to the TTL for each individual domain.

发布评论

评论列表(0)

  1. 暂无评论