When someone searches using a keyword on some search ENGINE, then you can get the keyword from CGI variable HTTP_REFERER. Well there is no standard that is followed while passing the keyword, Google, MSN, Live, Alexa passes it as "q=" in the http_referer, Yahoo passes it as "p=" and AOL passes it as "query=", some engines pass it along the like if you search for something on Answers.com, then you will have http_referrer as http://www.answers.com/searchstring.
The second CGI variable that you will need is REMOTE_ADDR which will give you the IP of the location from where the visitor came from.
So our first step will be to get the KEYWORD and the Search Engine name from the Http_Referer, this can be done using REGULAR expressions and using REFind and MID string functions. Basically depending on your search engine, you find the occurrence of "q=", "p=" or "query=" and then URLDECODE the string to get the keyword.
So now you have the IP, KEYWORD and The Search Engine name. The next thing is you need to get the location from where the IP came from, I did some google work and came across the post from http://www.bpurcell.org/blog/index.cfm?mode=entry&entry=1099, the post is self explanatory and even has all the required files for you to get the location based on the IP address, and it is pretty accurate. You can download all the required files and just use the code as it is, also everything given on his post is free for download.
The next is you need is to map everything on GOOGLE maps, again you can find a custom tag for it on http://cfgooglemap.riaforge.org/, this is pretty simple to use and has lots of examples to choose the configurations you need.
That gives you everything you need, Location, IP, search engine, keyword and a MAP.
I will be adding more enhancements to it and if you need the code to get the KEYWORDS and search engine, then just send me an email and I will send it across to you, although it is pretty simple.
Post a Comment