ocpaul20 Posted January 20, 2008 Share Posted January 20, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/86894-solved-looking-to-get-the-google-keywords-used-logfile-referrer-entries/ Share on other sites More sharing options...
ratcateme Posted January 20, 2008 Share Posted January 20, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/86894-solved-looking-to-get-the-google-keywords-used-logfile-referrer-entries/#findComment-444243 Share on other sites More sharing options...
ocpaul20 Posted January 20, 2008 Author Share Posted January 20, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/86894-solved-looking-to-get-the-google-keywords-used-logfile-referrer-entries/#findComment-444251 Share on other sites More sharing options...
ratcateme Posted January 20, 2008 Share Posted January 20, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/86894-solved-looking-to-get-the-google-keywords-used-logfile-referrer-entries/#findComment-444254 Share on other sites More sharing options...
ocpaul20 Posted January 20, 2008 Author Share Posted January 20, 2008 Ok, I think I found the answer here it seems they are in the referrer string but different for each search engine maybe. Quote Link to comment https://forums.phpfreaks.com/topic/86894-solved-looking-to-get-the-google-keywords-used-logfile-referrer-entries/#findComment-444258 Share on other sites More sharing options...
GingerRobot Posted January 20, 2008 Share Posted January 20, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/86894-solved-looking-to-get-the-google-keywords-used-logfile-referrer-entries/#findComment-444259 Share on other sites More sharing options...
ocpaul20 Posted January 20, 2008 Author Share Posted January 20, 2008 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>"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/86894-solved-looking-to-get-the-google-keywords-used-logfile-referrer-entries/#findComment-444278 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.