Forum Moderators: coopster & phranque

Message Too Old, No Replies

Displaying search phrase

         

maccas

7:23 am on Oct 21, 2001 (gmt 0)

10+ Year Member



Is there anyway to strip the search phrase that a user came to my site on and display this phrase on my page? I thought it could be done by SSI, perl maybe? Thanks.

JuniorHarris

4:39 pm on Oct 21, 2001 (gmt 0)

10+ Year Member



I assume you are talking about referrals from search engines.

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.

gethan

5:05 pm on Oct 22, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is possible in both PHP and Perl (and many others).

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.

JuniorHarris

8:33 pm on Oct 23, 2001 (gmt 0)

10+ Year Member



What gethan said!

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!~;)