looking to capture all search engine keywords

Discussion in 'PHP' started by ianternet, May 27, 2008.

  1. #1
    I need to dynamically insert a search engine keyword into any website and from any search engine. I want these keywrods to be dynamically inserted in a affilaite link or my tracking link so I can see what keywords are being triggered to either land on my website and make them click.

    I found seperate php scripts for google and yahoo none really for all three or all search engines. I want to see if there is a php script that is out there whcih pulls the search query from the search url and grab that keyword and insert it anywahere in the page or link

    someone searches: blue widget from yahoo msn google etc

    goes to my page: dynamically inserts blue widget into aff link ?subid=blue widget

    if no keyword leave blank

    thanks
     
    ianternet, May 27, 2008 IP
  2. ErectADirectory

    ErectADirectory Guest

    Messages:
    656
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    $se=seReferer(); 
    
    function seReferer($ref = false){
        $SeReferer = (is_string($ref) ? $ref : $_SERVER['HTTP_REFERER']);
        if( //Check against Google, Yahoo, MSN, Ask and others
            preg_match(
            "/[&\?](q|p|w|searchfor|as_q|as_epq|s|query|sTerm|Keywords)=([^&]+)/i",
            $SeReferer,$pcs)
        ){
            if(preg_match("/https?:\/\/([^\/]+)\//i",$SeReferer,$SeDomain)){
                $SeDomain    = trim(strtolower($SeDomain[1]));
                $SeQuery    = $pcs[2];
                if(preg_match("/[&\?](start|b|first|stq)=([0-9]*)/i",$SeReferer,$pcs)){
                    $SePos    = (int)trim($pcs[2]);
                }
            }
        }
        
        if(!isset($SeQuery)){
            if( //Check against DogPile
                preg_match(
                "/\/search\/web\/([^\/]+)\//i",
                $SeReferer,$pcs)
            ){
                if(preg_match("/https?:\/\/([^\/]+)\//i",$SeReferer,$SeDomain)){
                    $SeDomain    = trim(strtolower($SeDomain[1]));
                    $SeQuery    = $pcs[1];
                }
            }
        }
        // We Do Not have a query
        if(!isset($SeQuery)){ return false; }
        $OldQ=$SeQuery;
        $SeQuery=urldecode($SeQuery);
        // The Multiple URLDecode Trick to fix DogPile %XXXX Encodes
        while($SeQuery != $OldQ){
            $OldQ=$SeQuery; $SeQuery=urldecode($SeQuery);
        }
        //-- We have a query
        return array(
            "Se"=>$SeDomain,
            "Query"=>$SeQuery,
            "Pos"=>(int)$SePos,
            "Referer"=>$SeReferer
        );
    }
    PHP:
    at the top of the page then

    
    echo $se['Query'] ; // prints the query string (keyword)
    echo $se['Se'] ; // prints the search engine
    echo $se['Pos'] ; // prints the page number (untested)
    echo $se['Referer'] ; // prints the entire referring page
    
    PHP:
    Not my script, found it somewhere but it's worked awesome in the past. Hope this helps everyone out.
     
    ErectADirectory, May 28, 2008 IP
  3. ianternet

    ianternet Well-Known Member

    Messages:
    1,084
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    138
    #3
    wow you are friggin awsome! nice find!
     
    ianternet, May 29, 2008 IP
  4. ErectADirectory

    ErectADirectory Guest

    Messages:
    656
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yep, I remember having a joygaism when I first ran across it. You can easily use the keywords extracted to insert into your tracking stuff ... I might suggest you trying to mask it however as aff networks are known to use the data that affiliates provide for their own good (eg steal your keywords).

    You can easily insert those words into a db with a random interger. Pass the random # to the network instead of the keyword. this will keep your words anonymous
     
    ErectADirectory, May 29, 2008 IP