Seen this in wordpress, how to do on other sites?

Discussion in 'PHP' started by Jboo, Nov 19, 2007.

  1. #1
    Hi,

    I've seen this done in a plugin for wordpress and would like to accomplish the same with a regular site. What I would like to do is create a PHP script that displays the referring search engine and keyword that was used to find my site.

    So say someone found my site using Google and used the keyword "widgets" I could display the words for the referring engine (Google) and the keyword (widgets) on the webpage somewhere.

    I'm useless at PHP :(, but could anyone point out if this is easy to create?

    Thanks for any replies.
     
    Jboo, Nov 19, 2007 IP
  2. Fash

    Fash Peon

    Messages:
    37
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This is a pretty simple version, but it ought to do the trick.

    
    if(strpos($_SERVER['HTTP_REFERER'], "google.com/search") !== false){
    	$keyword = array_pop(explode("&q=", $referer));
    	echo(htmlentities(urldecode($keyword)));
    }
    PHP:
     
    Fash, Nov 19, 2007 IP
  3. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #3
    just check the wordpress plugin and source code should be there
     
    commandos, Nov 19, 2007 IP
  4. Jboo

    Jboo Active Member

    Messages:
    229
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Thanks Fash, this currently doesn't display anything on the page when I test being referred from Google though. I'll try and look a bit further into this and see what the problem might be. This looks exactly what I need (with MSN and Yahoo included) so I'm eager to get this working.

    Thanks for the help.

     
    Jboo, Nov 20, 2007 IP
  5. lfhost

    lfhost Peon

    Messages:
    232
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #5
    $referer is not defined unless you have register_globals on.

    if(strpos($_SERVER['HTTP_REFERER'], "google.com/search") !== false)
    {
        $keyword = array_pop(explode("&q=", $_SERVER['HTTP_REFERER']));
        echo(htmlentities(urldecode($keyword)));
    }
    PHP:
     
    lfhost, Nov 20, 2007 IP
  6. Jboo

    Jboo Active Member

    Messages:
    229
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #6
    Ah, it's working now, thanks!
     
    Jboo, Nov 21, 2007 IP