Forum Moderators: coopster & phranque

Message Too Old, No Replies

getting query string

CGI - get query

         

smallcompany

6:55 am on Nov 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



We have CGI script that carries variables (keywords) around site and if the traffic goes out, PHP file that is used for outgoing links “grabs” a variable and forwards it out (if needed).

Our problem is that, for keyword variable, we can get only what we forward from traffic source. For example if we get traffic from Google AdWords, we can use our keyword as variable. If we use phrase or broad match, our keyword may be way different than real query. My question is:

How can we grab real query from Google (referrer URL, “q”) and insert that at the end of our site’s URL as a variable? How would you resolve that with Perl/CGI?

Thanks

Dabrowski

1:22 pm on Nov 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I believe the full URL will be stored in $ENV{HTTP_REFERER} and you can easily use a regex to extract the 'q' parameter.

Something like:
$ENV{HTTP_REFERER} =~ m/q=(.*?)(&¦$)/

Should put the query string into $1.

smallcompany

4:54 am on Dec 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The script has been done by a coder and it is being tested. The script works in the way that it maintains referring domains and their query variables. For example, for Google it is “q”, while for Yahoo it is “p”.

Now, I noticed that if we have part of the code in form:

"search.live.com" => "q",

it grabs the query string and takes it to our site.

But, if I change it to

"live.com" => "q",

it does not do it.

I sent this question to a coder that created this part. We'll see what he says.

Still, I wonder if you would know why this happens in this way? Is this about way of how coding has been done, or it has to do how CGI/Perl works?

If it’s about coding, I am guessing it may be about this part:

$url =~ /http:\/\/([^\/]+)\/(.+)/;

Although not a coder myself, this looks like it says “something after [...]

Would that be why I need the full name of referring domain?

Thanks