cromagnon Posted June 3, 2010 Share Posted June 3, 2010 Hi all I like a script that can Show Google Search Term That Brought Visitor to my Website. Example: People search for "flower baskets" and find my page in google result list. They pres the Google links and get to my page. Here they will read: "You find this page by seachring for "flower baskets". I found this script, but it seems like its not working: <?php $referer= $_SERVER['HTTP_REFERER']; //find the search query from google that brought them here $qref= strpos($referer,'google'); if($qref!="){ $qstart= strpos($referer,'q='); $qend= strpos($referer,'&',$qstart); $qtext= substr($referer,$qstart+2,$qend-$qstart-2); $qtext= str_replace('+',' ',$qtext); } echo $qtext ?> Can anyone help me to fix the script or bring me a new script for this task? Thanks in advance Cromagnon Quote Link to comment https://forums.phpfreaks.com/topic/203744-show-google-search-term-that-brought-visitor-to-my-website/ Share on other sites More sharing options...
ignace Posted June 3, 2010 Share Posted June 3, 2010 if (isset($_SERVER['HTTP_REFERER'])) { $query = array(); parse_str(parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY), $query); print $query['q']; } Quote Link to comment https://forums.phpfreaks.com/topic/203744-show-google-search-term-that-brought-visitor-to-my-website/#findComment-1067115 Share on other sites More sharing options...
cromagnon Posted June 3, 2010 Author Share Posted June 3, 2010 Thanks. Very nice! It works. But it prints danish letters a little strange. Like: gucci bælter It should be "gucci bælter". How can I be sure that danish letters æ, ø, å will be written the correct way in the script? Thanks!!! Quote Link to comment https://forums.phpfreaks.com/topic/203744-show-google-search-term-that-brought-visitor-to-my-website/#findComment-1067141 Share on other sites More sharing options...
ignace Posted June 3, 2010 Share Posted June 3, 2010 How does it show up in your source? It's possible you set the wrong character set. Quote Link to comment https://forums.phpfreaks.com/topic/203744-show-google-search-term-that-brought-visitor-to-my-website/#findComment-1067224 Share on other sites More sharing options...
cromagnon Posted June 3, 2010 Author Share Posted June 3, 2010 I am not sure I understand what you mean... When people are searching for "gucci bælter" in google, the script print it this way on the page "gucci bælter". And that is wrong. Can I fix it? Quote Link to comment https://forums.phpfreaks.com/topic/203744-show-google-search-term-that-brought-visitor-to-my-website/#findComment-1067236 Share on other sites More sharing options...
ignace Posted June 3, 2010 Share Posted June 3, 2010 I am not sure I understand what you mean... How does it show up in your HTML source? FF&IE: View > Source Quote Link to comment https://forums.phpfreaks.com/topic/203744-show-google-search-term-that-brought-visitor-to-my-website/#findComment-1067322 Share on other sites More sharing options...
cromagnon Posted June 3, 2010 Author Share Posted June 3, 2010 Actually the same as printed in browser: gucci bælter :-\ Quote Link to comment https://forums.phpfreaks.com/topic/203744-show-google-search-term-that-brought-visitor-to-my-website/#findComment-1067334 Share on other sites More sharing options...
ignace Posted June 3, 2010 Share Posted June 3, 2010 Actually the same as printed in browser: gucci bælter :-\ Does your server host Windows? If so, then try: setlocale(LC_ALL, ''); Otherwise you can try: setlocale(LC_ALL, 'se_SE'); Quote Link to comment https://forums.phpfreaks.com/topic/203744-show-google-search-term-that-brought-visitor-to-my-website/#findComment-1067342 Share on other sites More sharing options...
cromagnon Posted June 3, 2010 Author Share Posted June 3, 2010 Its apache, but no, its unfortunately not working Is it really not possible to use foreign fonts?! Quote Link to comment https://forums.phpfreaks.com/topic/203744-show-google-search-term-that-brought-visitor-to-my-website/#findComment-1067357 Share on other sites More sharing options...
ignace Posted June 4, 2010 Share Posted June 4, 2010 Its apache, but no, its unfortunately not working Is it really not possible to use foreign fonts?! Sure, but you need to have them installed. And you need to know where your users are from so can you switch the locale to theirs. Quote Link to comment https://forums.phpfreaks.com/topic/203744-show-google-search-term-that-brought-visitor-to-my-website/#findComment-1067553 Share on other sites More sharing options...
cromagnon Posted June 5, 2010 Author Share Posted June 5, 2010 The users will be from Denmark mostly. How can I install it? Quote Link to comment https://forums.phpfreaks.com/topic/203744-show-google-search-term-that-brought-visitor-to-my-website/#findComment-1068320 Share on other sites More sharing options...
shb Posted June 28, 2010 Share Posted June 28, 2010 I would need a similar code to this one but I wank to track the searched query in Custom Google Search on my website. Is that possible? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/203744-show-google-search-term-that-brought-visitor-to-my-website/#findComment-1078290 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.