tags:

views:

283

answers:

6

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?

+9  A: 

Unfortunately, this is possible.

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

SLaks
@SLaks: Hmmm... Interesting
Daniel Vassallo
+1. Although I believe recent versions of Firefox have partially shut off this "feature".
casablanca
cool trick, thanks. I'm not looking to invade visitor privacy though, I just need to do this for a strictly technical reason.
Lilacs
+1, although Safari 5 has removed the `:visited` selector to remedy this problem.
kingjeffrey
+6  A: 

You can sort of do it (with JavaScript and the CSS psuedo class :visited), but browsers are fighting back.

I wouldn't rely on using this method, and it does raise privacy concerns.

alex
I like it how you provide it is possible and the problems, rather than just one or the other. Good work.
balupton
@balupton Thank you!
alex
lol, the first link's graph shows how it can be beneficial to have software that runs slow - the slower the better :) IE is the best browser in the world from that viewpoint.
Anurag
+3  A: 

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

nathan
wait, isn't that what Google and MS CDN's already do?
Anurag
*wonders why I never thought of that before going to CSS hacks.
TheLQ
+3  A: 

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"&gt;&lt;/a&gt;
<a href="http://www.amazon.com"&gt;&lt;/a&gt;

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.

Anurag
A: 

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.

sarnold
I don't know how reliable this would be. Don't a lot of ISPs have their own DNS caches which many users use?
alex
BTW, I think you confused my name. I don't go by Eric (anymore) :P
alex
@alex *sigh* not sure how I screwed that up :) sorry
sarnold
@sarnold Quite alright :D
alex
A: 

Yep, try this out. The CSS history hack works well. Currently firefox recognizes this as a vulnerability and they are working on a patch. Other browsers don't care. Its a safe bet that IE and Safari will never fix it.

Rook
Why do you think Safari will never fix it?
alex
`https` links don't seem to give up that information here.
Anurag
Safari 5 is the only browser that has fixed this. They've removed `:visited` completely.
kingjeffrey
@alex (http://www.reddit.com/r/netsec/comments/cqyd1/apple_ranks_number_1_in_security_bugs/)
Rook
@The Rook Thanks for the link.
alex