#1
  1. Contributing User
    SEO Chat Explorer (0 - 99 posts)

    Join Date
    Jun 2003
    Location
    Romania
    Posts
    89
    Rep Power
    16

    extracting the query words from google referrer url ??


    I want to display some content on my page depending on what the user searched on google.
    I have noticed that the query words are sometimes in the q other times in the as_epq variable. Does anybody know ant other or the best way to this in php.
  2. #2
  3. No Profile Picture
    Contributing User
    SEO Chat Explorer (0 - 99 posts)

    Join Date
    May 2003
    Location
    Northern New Jersey
    Posts
    32
    Rep Power
    16
    I'm sure there is a nicer way to go about this... but this seems to work.

    -= John


    Code:
    <?
    
    // $referer = getenv("HTTP_REFERER");
    
    // this is an example referer for testing. remove this and un-comment the line above
    $referer = "http://www.google.com/search?hl=en&ie=ISO-8859-1&q=its+too+hot+in+new+jersey";
    
    $string = explode("&", $referer);
    
       while(list($key,$value) = each($string)){
       if (preg_match("/q=/i", "$value")){
    
       $search_string = eregi_replace("q=","",$value);
       $search_string = eregi_replace("\+"," ",$search_string);
       echo "$search_string";
       }
       }
    
    ?>
  4. #3
  5. Contributing User
    SEO Chat Explorer (0 - 99 posts)

    Join Date
    Jun 2003
    Location
    Romania
    Posts
    89
    Rep Power
    16
    Thank you very much for your reply. I have tested your code and it works great for normal searched but when it is a custom search the result is not so good.

    Here is an example:
    http://www.google.com/search?as_q=search+engine+frendly+urls&num=10& amp;hl=en&ie=UTF-8&oe=UTF-8&btnG=Google+Search&as_epq=&as_oq=&am p;as_eq=&lr=&as_ft=i&as_filetype=& as_qdr=all&as_occt=any&as_dt=i&as_site search=&safe=images
    --->> http://www.google.com/search?as_search engine frendly urlsas_epas_oas_e

    Google is changing the vars: q becomes as_q. So the problem I have is a little bit more complicated.

    Has someone noticed other vars that define the searched text.
  6. #4
  7. No Profile Picture
    Contributing User
    SEO Chat Explorer (0 - 99 posts)

    Join Date
    May 2003
    Location
    Northern New Jersey
    Posts
    32
    Rep Power
    16
    Looks like the "as_q" variable is the result of a typo in your search string.

    as_q=search+engine+frendly+urls

    If you click on the example link to Google you provided below,
    the results page presents you with a Did you mean:" link to search with the correct spelling.

    Click the "Did you mean" link. The "as_q=" variable is now the correct "q=" you've expected.

    -= John

    PS - You can simply add a "elseif" clause to that code which will check for both.

    -= J
  8. #5
  9. Qeustoin Eevyrhtnig.
    SEO Chat Adventurer (500 - 999 posts)

    Join Date
    May 2003
    Location
    Brisbane, Australia
    Posts
    518
    Rep Power
    44

    asp?


    is it possible to do this in ASP?
  10. #6
  11. No Profile Picture
    Contributing User
    SEO Chat Explorer (0 - 99 posts)

    Join Date
    May 2003
    Posts
    45
    Rep Power
    16
    I've done this for my website.

    - I created a database of all search engines that i could find. I used my logs for that.

    - one table holds all possible urls for a search engine

    - Another table holds the possible variable that goes with one search engine (q, as_q, etc... for google, p for yahoo and more)

    - When someone hits my webpage with a referer included a program searches in the database and extracts the keyword found in the variable associated with a search engin.

    < other extensive stuff done here >

    - I then return the best possible page for that visitor
    Last edited by Cesam; Jun 27th, 2003 at 01:10 PM.

Similar Threads

  1. Google Friends Newsletter December
    By Phoenix in forum Search Engine Optimization
    Replies: 1
    Last Post: Dec 5th, 2003, 11:50 PM
  2. Google End?
    By analogik in forum Google Optimization
    Replies: 12
    Last Post: Sep 17th, 2003, 07:37 PM
  3. Google and query strings
    By Biffy in forum Google Optimization
    Replies: 5
    Last Post: Jul 8th, 2003, 03:50 AM
  4. Buzz abounds on Google IPO
    By ctn in forum Google Optimization
    Replies: 0
    Last Post: Jun 14th, 2003, 10:20 PM

IMN logo majestic logo threadwatch logo seochat tools logo