If so, you should be able to parse the values from the (IIS) http_referer server variable. This may not be an easy task, as some engines have several referral formats. But it could be possible, and very similar to how log analyzers extrapolate keyword information. The only difference is this would have to be accomplished real-time to display the phrase on the page, so you want to ensure it does not impede performance.
As JuniorHarris says - it may impede server performance. The biggest problem is that every referrer will have a different section that includes the keywords. You'll have to pattern match differently for each domain -- getting that info as well will be a huge task.
eg.
if ($HTTP_REFERRER =~ /google.co/i) {
$HTTP_REFERRER =~ /&q=(.*?)[&¦$]/;
$kw = $1;
} elsif ($HTTP_REFERRER =~ /msn.co/i) {
$HTTP_REFERRER =~ /&query=(.*?)[&¦$]/;
$kw = $1;} elsif .......
}
And thats a gross over simplification... lots and lots of exceptions. Best way would to be to find a GPL log analyzer and steal that section of code (maintaining any credit where it belongs :))
Good luck - if you do get something going -- let me know I'd be interested in the same kind of thing.
You could consider including the domain/strings in a flat file or database record. Possibly even leveraging a standard format used by any popular log analyzer.
The web app could read this on startup, loading a single copy into memory. Then the code could utilize a loop for comparing domain string matches (/google.co) and extracting the corresponding (search) query string value (q=).
This may provide better performance, but most importantly it would allow for additions without having to modify the source code every time!~;)