Forum Moderators: coopster

Message Too Old, No Replies

getting the search query

no equal signs but backslashes in url only

         

smallcompany

8:36 pm on Nov 14, 2008 (gmt 0)

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



I use PHP to get the search query strings from HTTP referrer.

In my code I have an array for SEs, and I do it in this way:

"google" => "q:G"
"yahoo" => "p:Y"

By a fairly small exercise, the referring URL gets extracted from $_SERVER['HTTP_REFERER'], compared to what’s in the array, and it goes from there.
As an output, I’ll have that G for Google, Y for Yahoo and so on. I put it wherever I want, pass it through, right it into a file, whatever.

I also have a part that checks on SEs I don’t have on the list (in the array). If that is the case, I get their URL passed through. That way, I can go to that SE, check how they mark their query string and add it into my code.

Finally, in some cases I came across those that do not use the form “q=KEYWORD” but .../q/KEYWORD/...

How do I extract it from there? I don’t feel I could put it into array straight from $_SERVER['HTTP_REFERER'] like I do with Google or any other that is using the form KEY=VALUE.

What do you do in this case? Or what is your suggestion?

Thanks

vincevincevince

4:25 am on Nov 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



/q/KEYWORD/ - these can probably be used as is - look for a string starting after /q/ and stopping before the next /.

Test the engine to see how they encode spaces and non-alphanumeric characters - they probably become _ or - and so you should do a quick str_replace() to substitute _ or - to ' ' before writing to your log.

smallcompany

8:31 pm on Nov 16, 2008 (gmt 0)

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



So, I could do regex to extract the value based on "key" and "value" I would setup in array just like for other SEs.

Thanks