Reputation: 9998
When I search for something such as "rearrange table columns in asp.net
" on Google, and click the link to Wrox's forum site, the site greets me with a message such as "Your Google search for 'rearrange table columns in asp.net' brought you to Wrox Forum...".
How does a site know what query I typed into Google? And how could I add such an ablity to my site?
Upvotes: 2
Views: 875
Reputation: 52533
Like these guys are suggesting, it's the HTTP_REFERER
header variable. The query is in the "q" key in the URL. So if you want to parse that, you can just sort out the querystring and URL decode the "q" variable.
Upvotes: 2
Reputation: 38714
It uses a header known as the "HTTP referrer". See http://en.wikipedia.org/wiki/HTTP_referrer
To use it in your site, you would need some kind of dynamic page generation, such as ASP / ASP.NET, PHP, or Perl. For example in Perl, you could do something like:
if ($ENV{HTTP_REFERER} =~ /google.com\?.+&q=(.+?)&/)
print "Your google search of $1 brought you to this site";
WARNING: The code above is only an example and may not be correct or secure!
Upvotes: 8
Reputation: 75717
It looks at the referrer header. Here is some fairly basic PHP code to do it.
Upvotes: 1
Reputation: 86094
It is parsing your query from the query parameters in the HTTP_REFERER
server variable, which contains the URL you're coming from and is provided in your HTTP request.
Upvotes: 12