Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Posts
    571
    Thanks
    25
    Thanked 28 Times in 28 Posts

    Get Keyword Person Used on Google To Find Your Site

    Hey, This is a code that will store the keyword a person used on google to find your site:
    PHP Code:
    <?php

    // Get The URL and use parse_url to get an array of info about it
     
    $url parse_url($_SERVER['HTTP_REFERER']);

    //If  from Google Get query & Keywords
    if ($url['host'] == 'www.google.com')
    {
        
        
    $query $url['query'];
        
    $param_array explode('&',$query);
        foreach (
    $param_array as $param)
        {
            if (
    $param{0} == 'q'// if first char is q, it's your google query.

            
    {
                
    $word_string substr($param2); // strip 'q='
            
    }
        }
        
    $word_string str_replace('"'''urldecode($word_string));

        
    $words explode(' '$word_string);

        echo 
    "<pre>\n";
        
    print_r($words);
        echo 
    "</pre>\n";
    } else 
    //If not from google tell them so
    {
        echo 
    "you are not coming from google";
    }

    ?>
    if their is a better way to do this please inform me! Main problem with this is that if person did not use google.com (ie: google.ca or somthing) then the script does not think they are from google.

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by srule_ View Post
    if their is a better way to do this please inform me! Main problem with this is that if person did not use google.com (ie: google.ca or somthing) then the script does not think they are from google.
    yes, is a better way. The main problem here is the idea, your content must have the proper title, not a title generated by users random search. You probably expect to increase relevance but in fact will not, trust me.
    This problem is not solved at the level of se and they don't expect to find a solution, at least, few years from now.
    About the script, don't work in more many situation, google have many domains not only com and ca, work with ip not only with dns and also for mobile, and this is only about google. We don't talk about other two major se Yahoo and MSN and also we don't talk about not having referer.
    We don't talk also about the fact that making this to work will increase the page loading time and this will decrease the number of visitors.
    Seems stupid but the content with the proper title is the single thing that works.
    Sorry that I dissipoint you

    best regards

  • #3
    Regular Coder
    Join Date
    Jul 2007
    Posts
    571
    Thanks
    25
    Thanked 28 Times in 28 Posts
    Good points, will this effect SEO too? Like when a googlebot crawls a site with this code what would they see?

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by srule_ View Post
    Good points, will this effect SEO too? Like when a googlebot crawls a site with this code what would they see?
    because bot see something else then users, this is cloaking, a old trick of blakhat seo. People can say that google penalize you for that few month, half year or more,
    I think that google will try to restore the search relevance and this is a slow process.

    best regards

  • #5
    Regular Coder
    Join Date
    Jun 2008
    Location
    SE Wisconsin, US
    Posts
    222
    Thanks
    1
    Thanked 20 Times in 20 Posts
    At one time, I remember seeing a site that posted referred parsing code for Google, Yahoo and MSN URLs. It included ASP.Net code, but it would probably be easily adaptable to PHP. I will look this morning and post it here if I can find it. I want to say that it was at codeproject.com.
    Milwaukee Web Designer and SEO Milwaukee Firm specializing in ASP.Net, C#, VB.Net, SQL Server and Access.

  • #6
    New Coder
    Join Date
    Nov 2007
    Location
    Thane-Vashi,Mumbai,India.
    Posts
    44
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Better code:
    PHP Code:
    <?php
    $parsed_url
    =parse_url($_SERVER['HTTP_REFERER']);
        if(
    stripos($parsed_url['host'],'google'))
        {
        
    parse_str($parsed_url['query'],$parsed_query_string);
        
    $keyword_string=$parsed_query_string['q'];
        
    $keyword_string=explode('',$keyword_string);
        }
    ?>

  • #7
    New Coder
    Join Date
    Nov 2007
    Location
    Thane-Vashi,Mumbai,India.
    Posts
    44
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Better code:
    PHP Code:
    <?php
    $parsed_url
    =parse_url($_SERVER['HTTP_REFERER']);
        if(
    stripos($parsed_url['host'],'google'))
        {
        
    parse_str($parsed_url['query'],$parsed_query_string);
        
    $keyword_string=$parsed_query_string['q'];
        
    $keyword_string=explode('',$keyword_string);
        }
    ?>

  • #8
    New Coder
    Join Date
    Mar 2009
    Location
    Texas
    Posts
    13
    Thanks
    3
    Thanked 1 Time in 1 Post
    The exploded string returns "Array", literally.

    This works:
    PHP Code:
    <?php
    $parsed_url
    =parse_url($_SERVER['HTTP_REFERER']);
        if(
    stripos($parsed_url['host'],'google'))
        {
        
    parse_str($parsed_url['query'],$parsed_query_string);
        
    $keyword_string=$parsed_query_string['q'];
        }
    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •