Sticky Posts
Apr 25, 2009
Search Engine Query Information From HTTP Referrer With PHP
Search engines send traffic your way (unless you really fked things up) and knowing what people search to find you is both fun, cool and extremely important for your bucks. To be on top of things you must be aware of what searches point your way and identify potential within them. But http referrer string parsing is not really easy and it's always easier to use someone else's. I couldn't find a valid someone else's when I wrote mine so this is made in-house for you ... and me (well me ... then you).
It used to be published on my old blog and worked mostly with RegExp. Now I changed the core and use parse_str where I used complicated RegExps. It's easier to read and handle for anyone. It also handles the new Google query with the /url? thing.
Finding The Search Engine Query From Referrer
Read the inner comments (it's fully commented) as they tell all you need to know. The function returns an object (to make it an array just typecast it: (array)function()) and, if verified referrer is current referrer, it marks some PHP define's into PHP execution eternity so these can be used by other functions down the road easily.
Registration is quick, painless and worth its weight in gold.
Heads up to bluehat seo on this one. Don't teach your readers to RegExp referrers... teach them the 5ubliminal way.


Awesome, thanks for the new version of the script.
It took me awhile, but I used your function to implement BlueHatSeo’s Dynamic SEO idea. So far the script is only changing the page title, h1 tag, and adding some tags at the bottom of the content. I see a bunch of potential with it though. Thanks!
You’re welcome :)
Hi,
Interesting subject.
Does your ‘friend’ Yoast do it differently? enhanced-wordpress-contact-form
He claims to collect very interesting data in regards to referrer info including PPC conversions?
Now that would be very cool. Can you do it?
Thanks
You lost me. I don’t get it why you added that link here. Advanced contact form on a search referrer analysis script page…
I don’t do PPC … at all. This is for extracting search queries from HTTP referrer. I don’t know what data Google sends on AdWords click … if I did I could do it but … I don’t give a flyin’ fk about PPC.
PPC Conversion Tracking … lemme guess: Track visitors coming from PPC campaigns and see what they do on your site. This script will let you see where they come from, tracking them … is for you :)
PS: Doesn’t Google offer PPC conversion analysys with Google Analytics?
OK, but his form collects all referrer info, not just for PPC.
It will help if you use the contact form for collecting leads, and want to know which site referred them and also search keywords for SEO purposes.
Dunno how it’s done, leave that to clever peeps like yourself.
But I would love some copy-paste solution to add into my own forms on other sites not running Wordpress.
I bet RentACoder.com could handle it ;) for a couple of bucks.
I’d rather donate to your blog, and thought it was related to this post anyway. My bad.
Let me tell you a secret. Nobody donates!
PS: I’m not for hire, nor do I do custom work for anyone unless I like the idea and need something like that, in which case I give the script away for free to the idea man.
The other secret…?
Nobody clicks on f!)&#(@#)(*$king ads either.
So true. Only chance is to seel something yourself … otherwise … it’s called charity.
Yeah, my “successes” have been with self made/marketed products.
I have to say that I like your style in this regard. More product ideas keep percolating in my head…now to find the time.
“Now I changed the core and use parse_str where I used complicated RegExps. It’s easier to read and handle for anyone.”
Offtopic a smidge…
Anything that removes the straight up pain in the ass that Regexps is…is good in my book.
I’m sorry I don’t get how I can return the query?
Do I just do:
$ref = el_http_seReferer();
echo($ref[2]);
Obviously not because that doesn’t seem to be working..
$ref is an object :) User var_dump($ref) to see it. You need $ref->Query. All go with -> in an object.