Gossamer Forum
Quote Reply
get search Term
Hi everyboby

do everyone knows a Plugin that can get the search Term from referrer URL (ex. Google search)

Marina
Quote Reply
Re: [mkoenig] get search Term In reply to
Depending on where you want to call this, you could create a new global.. and call it with <%global_name%>. Put the following code in it;

Code:
sub {
my $referer = $ENV{HTTP_REFERER'};
my $query;
$referer =~ m/query=(.*?)&/ and $query = $1;
return $query || "";
}

Remember, this requires you to be using either mod_rewrite, or page.cgi/search.cgi for the global to work correctly (as it obviously needs to be run in dynamic mode, to realise who referered the visitor).

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] get search Term In reply to
If the "query" parameter is the last one, that regex will fail...eg....

search.cgi?this=that&query=hello

...because there's no trailing "&".

I may be wrong but I think on some occasions the HTTP_REFERER variable will be undefined and so trying to perform a regex on it will trigger a warning.

Code:
sub {
require Links; import Links qw/$IN/; # I'm guessing on the package name as I don't use Links SQL.
my $referer = defined $ENV{HTTP_REFERER} ? $IN->unescape($ENV{HTTP_REFERER}) : '';
my $query = '';
if ($referer =~ m/query=([^&;]+)/) {
$query = $1;
}
return $query;
}
Quote Reply
Re: [Andy] get search Term In reply to
The problem with this, is that not all query variables are the same (obviously).

Common ones are (p, q, Keywords, search, query, term)

So I suppose you could modify it to say:

Quote:

$referer =~ m/[query|q|Keywords|p]=(.*?)&/ and $query = $1;


or something similar...

- Jonathan