Jump to content

[SOLVED] Looking to get the Google keywords used & logfile referrer entries


Recommended Posts

 

say you do a search on ' red green blue' on Google and it brings up your site as one of the results. the url of the Google search is

http://www.google.com/search?hl=en&q=red+green+blue&btnG=Search

 

1) if you click on that link to your site, how do you then get the keywords (red green blue) that were used to search Google for your site?

 

The search words must get passed to your site somehow, in some variable, don't they?

 

2) The log files show the referring url, but do they use the HTTP_REFERER (which cannot be relied apon) or does Apache use another method to get the url of the referring site that linked to yours (in the example above, it would be Google) ?

 

Thanks for any help.

Paul

Hey have you checked out google webmaster tools

www.google.com/webmasters/tools/

they are good for seeing how your site is being searched

 

 

I don't think the search terms are passed to your site because if you look at the url on the first wikipedia entry from 'red green blue':

http://www.google.com/url?sa=t&ct=res&cd=1&url=http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FRGB_color_model&ei=aDaTR57JCZCipwScx7GWDg&usg=AFQjCNHKtQSXRCqJYe0U35hPo5MGr3hIBg&sig2=Zdxdg91yIbn6wxb9_Hcj_A

you see you are being redirected to another page inside Google then sent to the wikipedia page this other page dose not record the search terms

 

Scott.

 

 

Thanks Scott,

yes I have checked out webmaster tools and this is good, but I need the info available to me using PHP.

 

There must be some way of getting at the search terms people have used to arrive at your site.

 

http://en.wikipedia.org/wiki/RGB_color_model

I dont know how you get that long link, because when I look at the first item on the page it gives the above as the destination.

 

 

 

If you right click the link and look at where it is taking you, it takes you to a Google page then quickly redirects you to Wikipedia or where ever so you are not linked from the main search page. and because you are redirected quickly you never see the other Google page.

 

Scott.

Indeed. You need to be checking the referring URL, and extracting the relevant information. Make sure your script doesn't expect the http referer to always be present, however.

 

As you rightly say, the referring url will be very different, depending on the seach engine.

a couple of mickey-mouse programs to demonstrate but obviously for search engines you need to change thinsg a bit. my programming is very basic and I copy and paste a lot. Thanks to everyone I have copied from in other posts.

 

<?php
// ===============================================================
// Name : 		.testreferrer1.php
// ================================================================
//This is testreferrer1.php
// to run this program call http://hostname/testreferer1.php?var1=123&var2=456&var3=789
?>

<HTML>
<HEAD>
</HEAD>
<BODY>
<A href="http://localhost/testreferrer2.php?newvar1=abc&newvar2=def&newvar3=ghi">this link=testreferrer2</A>
</BODY>
</HTML>

==============================

<?php
// ===============================================================
// Name : 		.testreferrer2.php
// ================================================================
echo "<BR>========referrer=====================<BR>";
    $ref = NULL;
    if(!$ref=@$HTTP_REFERER) {
        if (isset($_SERVER['HTTP_REFERER'])) {
            $ref=$_SERVER['HTTP_REFERER'];
        }
    }
echo $ref."<BR>";
$matches=array();
$url=$ref;
$pos1=strpos($url, '.php?');
$new_url=substr($url,$pos1+5,(strlen($url)-$pos1));

$param_array = explode('&', $new_url);
while (list($key, $val) = each($param_array)) {
    $subitem = explode('=', $val);
    echo '<BR>param:['.$subitem[0].'] = [';
    print_r($subitem[1]);
    echo ']<BR>';
}
echo "<BR>========referrer=====================<BR>";

echo "<BR>==========get===================<BR>";
if (isset($_GET)) {
    while (list($key, $val) = each($_GET)) {
        echo '<BR>get:['.$key.'] = [';
        print_r($val);
        echo ']<BR>';
    }
}
die("<BR>=== end of testreferrer2 ===== <BR>");
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.