Click here to Skip to main content
Click here to Skip to main content

Get search key word from the referrer url.

, 15 Nov 2010
Rate this:
Please Sign up or sign in to vote.
This is a very simple way to do actually. Web developers are very much familiar to work with the referrer url. The HTTP_REFERER server variable return the referrer url. In this tips I will show how easily we can get the search key word from the referrer url.
Well, lets take an example, you have a web site and the people come to your site from a search engin (Google, Bing) and now you want to know which word are used for the search and which search engin are used as well.
 
public string GetSearchKeyWords(string strQuery)
{
    string result = "";
    string pattern = "\\b\\w*p=(?!u)\\w*\\b|\\b\\w*q=(?!u)\\w*\\b|\\b\\w*qs=(?!u)\\w*\\b"
            + "|\\b\\w*encquery=(?!u)\\w*\\b|\\b\\w*k=(?!u)\\w*\\b\\b\\w*qt=(?!u)\\w*\\b"
            + "|\\b\\w*query=(?!u)\\w*\\b|\\b\\w*rdata=(?!u)\\w*\\b|\\b\\w*search_word=(?!u)\\w*\\b"
            + "|\\b\\w*szukaj|terms=(?!u)\\w*\\b\\b\\w*text=(?!u)\\w*\\b|\\b\\w*wd=(?!u)\\w*\\b|\\b\\w*words=(?!u)\\w*\\b";
    foreach (Match m in Regex.Matches(strQuery, pattern)) {
        // get the matched string
        string x = m.ToString();
        x = x.Substring(1, x.Length - 1);
        // collect all text
        result += x;
    }
    return result.Replace("=", "");
}
 
Input: http://www.google.com/url?sa=t&source=web&cd=7&ved=0CEQQFjAG&url=http%3A%2F%2Fwww.example.com%2F&rct=j&q=codeproject.com=uSLVTMm0JYXNhAewqbzjBA&usg=AFQjCNFtfSFIuj4fxnl8bD_bR2NgzDePGw&cad=rja

Output: 
codeproject.com

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Md. Marufuzzaman
CEO
Bangladesh Bangladesh
A highly experienced leader with successful track record of brand management, product innovations and corporate communication. Some successful product innovations have also achieved and awards “Most Valuable Professional” (MVP) at 2010 and 2011 by CodeProject.com and also selected as a mentor of CodeProject.com
 
Over ten years of professional experiences in ICT field having extensive experience in formulating corporate vision and long term strategy. Leading development related functions including design, services, data management and analytics, customer experience management, content services, digital analytics and optimization.
 
An individual with results-driven approach and relentless in pursuit of excellence from a business and organizational standpoint. Believes in transparency, commitment and teamwork.
 
Specialties: Developing client-server with multi-tier application, database design, web based business software solutions, enterprise applications, google analytics, etc., for Windows / Mac using Microsoft SQL Server, Oracle, MySql, PS, Visual C#, R, VB.NET, ASP.NET, PHP, API, MVC, WebAPI , Add-In Visual Basic etc,. I have also more than two years’ of strong experience in mobile-VAS (platform development).
Follow on   Twitter   LinkedIn

Comments and Discussions

 
GeneralI have just tried this script and it is only retuning the fi... PinmemberGuerrilla12313-Mar-11 14:35 
GeneralRe: Yes you are absolutely right...the url is valid and contain ... PinmentorMd. Marufuzzaman15-Mar-11 9:16 
GeneralReason for my vote of 5 Great tip :-) Pinmvpthatraja27-Nov-10 23:18 
GeneralReason for my vote of 5 Usefull Info Pinmemberbaskarcts23-Nov-10 6:00 
GeneralReason for my vote of 5 This is a good program. PinmemberLakshmi Narayana198722-Nov-10 17:44 
GeneralReason for my vote of 5 great Pinmemberevren22-Nov-10 1:43 
GeneralReason for my vote of 5 Good Work PinmemberAbdul Quader Mamun15-Nov-10 23:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 15 Nov 2010
Article Copyright 2010 by Md. Marufuzzaman
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid