Last 50 keyword referrers
And now the answer for why I wanted to get a function to extract search keywords. This script will list the last 50 search keywords to your site (just like the Little Green Footballs script to show the last 50 referrers). I just hacked the two together. ![]()
See demo here.
update 3/11/03: Version 2 - this will display the keywords like v1 - but with a link to where it came from.
See demo here | Download it here.
update 3/16/03 Bug fix in version 2. To upgrade, download the files and just replace lgf-reflog-searchv2.php with the one you're using. (remember to copy your chagnes (paths) over to the new file)
January 19th, 2003 at 4:49 am
Just a couple of site updates to report before we head off to bed…I added in that code (I blogged about last week) over in the sidebar that will show you entries that have just scrolled off the main page. It's under the recent comments section. I als…
January 19th, 2003 at 11:38 am
This is awesome! I changed it to 10 refers and used an include to show reflog-search.txt on the main page of the site. I've been wanting to put something like this on my page for a while, thanks for making it so easy.
January 19th, 2003 at 12:07 pm
Wow, that was fast. Many, many thanks.
Richard
January 19th, 2003 at 12:08 pm
I wanted a script that would let me show the recent search phrases that brought people to Edifying Spectacle. I asked on Scripty Goddess and Jennifer quickly hacked together Last 50 keyword referrers. Now if I can just find a dynamic TOC builder for my…
January 19th, 2003 at 11:36 pm
Hw quickly should these appear? I've searched for my site in a few search engines but none of the search terms are showing in the files yet. I'm assuming I've done something wrong until I find out if there's a delay….
January 19th, 2003 at 11:57 pm
scratch that. it works. a series of my stupidity. Forgetting to put the leading / and including the wrong file *doh!*
January 21st, 2003 at 11:31 pm
I installed this and discovered that most people don't find me by searching.
It's still a fun addition.
January 26th, 2003 at 3:04 pm
It's been a while since I've posted a "To Do" list, but since they really do seem to help keep
January 26th, 2003 at 9:40 pm
I did a few tweaks around the site tonight. I added the last 50 keyword referrers script to the stats
January 28th, 2003 at 5:07 pm
I commented above to say that I'm using this script as an includes on my page, but I'm having one small problem with it. Once or twice since I've implemented this, people have come to my site using really long search strings, such as:
cache:7nhzSTx7CJwC:www.bigbrother.net/~fleurchild/reads.htm Eliza Crinkle Not Martha
The result (being the really long URL with no spaces) breaks my layout. Is there any way to put in some sort of filter that weeds out these strings and deletes them before they show on my page? If I was a decent programer, I'm sure I could work that out on my own, but…I'm not, which is why I'm asking you.
January 28th, 2003 at 8:17 pm
Rickie - yes, easily.
Open up the "show-refs-search.php" page…
look for this line towards the bottom:
echo "$r\n"; // if not a direct request, link it up
replace that line with this:
echo substr($r,0,10);
echo "<br>";
Do you see the ($r,0,10) part… you can change the "10" to however many characters you want to limit it to when it displays.
January 28th, 2003 at 10:14 pm
Thank you so much!
I replaced the lines you said to, and while it did cut off the offending URL at such and such a number of characters, it also cut off perfectly normal search strings that happened to consist of several words. I didn't want that, so I looked up the substr function to see if there was any way to tweak it to my specifications…what I found, is the function substr_repace, which I used to replace all instances of : and / with a line break.
This is what I put in my code:
$rtwo = str_replace(":", "
", $r);
echo(str_replace("/", "
", $rtwo));
It's not much, but this is the first time I've ever done anything in PHP by myself, so I'm all kinds of happy.
You've been more helpful than you can know.
January 28th, 2003 at 10:15 pm
Blech, in my haste I forgot to convert the brackets to ascii…
$rtwo = str_replace(":", "<br>", $r);
echo(str_replace("/", "<br>", $rtwo));
January 28th, 2003 at 10:24 pm
Cool! I'm glad I could help (put in you the right direction at least)

I like your solution
January 31st, 2003 at 3:19 pm
I've looked and can't seem to find it… do you have the script for just the last 50 referers, and NOT 50 search engine keywords? Or is there a way to make the above script do both?
January 31st, 2003 at 3:35 pm
Will - that script (the original 50 referrers script) was written by little green footballs - he has the download there on his site….
January 31st, 2003 at 3:38 pm
I should add - to get the download - scroll down his page - on the left hand side - look for the "scripts" box - the script you want is called "lgf referrers"
February 2nd, 2003 at 3:45 pm
is there any way to link up the search keywords with the referring url?
February 8th, 2003 at 4:03 am
Quick and probably silly question: do you need to have the extensions of the pages you're *tracking* be ".php?" I know that the page with the include needs the ".php" extention — wasn't sure whether that was the case for anything/everything you'd want to track.
I've been having some problems with the script, but all of my site extensions are ".shtml" (except, natch, for the page with the include).
Thanks!
February 8th, 2003 at 7:29 am
Any page you want to track needs to have the include on it - therefore they would also need to be able to process php (so either a .php extension, or you've done that .htaccess trick to get a .html, or .htm, .shtml to also process .php)
.shtml will NOT process php otherwise. I'm guessing your page extension is .shtml because you're using standard asp or cgi type includes (<!#–include file="filename" etc…) if you want to get this page to process php, you'll have to change them to php type includes and then either change the extension to .php or do the .htaccess trick.
Make sense?
February 9th, 2003 at 12:12 am
Actually, perfect sense.
And many thanks!
March 4th, 2003 at 2:03 pm
: looking anxious : I hate to be a bother, but what should I remove and where should I put in Rickie Beth's lines of code to fix that long URL issue? I've tried about every variation — removing "echo "$r\n";" and replacing it with her lines, leaving it in and putting her lines in before it, etc., and nothing seems to be working. I know that "echo" means to output, and I know that earlier in the script we're replacing google with a blank space. I also understand the concept behind replacing the "/" and ":" with line breaks — that part makes sense — but I'm way confused about what should go where to make it happen properly.
Any assistance gratefully appreciated!
March 4th, 2003 at 2:23 pm
On the show-refs-search.php page - towards the bottom - look for this:
echo "$r\n"; // if not a direct request, link it up
replace that line with either this:
echo substr($r,0,10);
echo "<br>";
which will cut short anything longer than 10 characters.
OR you can replace it with this:
$rtwo = str_replace(":", "<br>", $r);
echo(str_replace("/", "<br>", $rtwo));
which will replace any ":" or "/" to a linebreak
March 10th, 2003 at 2:22 pm
Hi!
is there any way to link up the search keywords with the referring url?
Thanks SO much! I've been trying this for hours and I can't seem to get it working.
Thanks!
March 10th, 2003 at 3:09 pm
Another question, totally off-topic (sorry about that).
I saw you have a page between submitting a comment and the redirect to the original page. I would like to know how you did this, since I have problems with people clicking more then once, resulting in a flood of comments.
Thanks again!
March 11th, 2003 at 10:46 am
Gert - Yes, I'm working on it now, and will update the post with a "version 2" when I'm done.
(and as for your other question - It's part of the "subscribe to comments" script (available on thise site). The only problem here is that if people hit the back button, on some browsers, it will submit the comment again. So you're still not "safe"
March 11th, 2003 at 11:09 am
Version 2 has been added.
March 12th, 2003 at 12:12 pm
im not sure version 2 works…i am getting errors:
Warning: main(stats/lgf-search-functions.php) [function.main]: failed to create stream: No such file or directory in /.7/var/virtuals/tpg1/public_html/blog/stats/lgf-reflog-searchv2.php on line 38
Warning: main() [function.main]: Failed opening 'stats/lgf-search-functions.php' for inclusion (include_path='.:/usr/local/lib/php') in /.7/var/virtuals/tpg1/public_html/blog/stats/lgf-reflog-searchv2.php on line 38
Fatal error: Call to undefined function: extractkeywords3() in /.7/var/virtuals/tpg1/public_html/blog/stats/lgf-reflog-searchv2.php on line 41
March 12th, 2003 at 12:29 pm
I'm using it now on scriptygoddess, so I know that if the settings are done correctly it *does* work.
Did you point the path to your functions file correctly? you need to user server paths.
ie. /home/youraccount/public_html/scriptfolder/file.php
NOT just
/scriptfolder/file.php
March 12th, 2003 at 12:33 pm
Also - make sure you've changed all the pages you're supposed to have changed… there's an additional page you have to make a change to (that in v.1 you didn't) as well, there's a new file you have to add "functions.php" so make sure you upload all the files…
March 12th, 2003 at 1:10 pm
ok I'll use the server paths…that wasn't clear to me.
where is function.php? didn't see it in the zip.
March 12th, 2003 at 1:15 pm
I didn't give it to you!
LOL! Well, thats a problem… I just checked the zip, and it's not in there. New zip has been uploaded.
Sorry about that
March 14th, 2003 at 1:46 pm
still having trouble…
Warning: main(/blog/stats/lgf-search-Functions.php) [function.main]: failed to create stream: No such file or directory in /.7/var/virtuals/tpg1/public_html/blog/stats/lgf-reflog-searchv2.php on line 38
Warning: main() [function.main]: Failed opening '/blog/stats/lgf-search-Functions.php' for inclusion (include_path='.:/usr/local/lib/php') in /.7/var/virtuals/tpg1/public_html/blog/stats/lgf-reflog-searchv2.php on line 38
Fatal error: Call to undefined function: extractkeywords3() in /.7/var/virtuals/tpg1/public_html/blog/stats/lgf-reflog-searchv2.php on line 41
I have changed the files to full path and relative - neither works. Strange thing is that I use the lgf referrers script from the lgf just fine.
Do the scripts have to be in the same directory as the calling php file?
March 14th, 2003 at 4:59 pm
for those playing along - this was a path issue - fixed offline. Make sure you all use *server paths*
If you look at his error - you'll see:
main(/blog/stats/lgf-search-Functions.php)
and then this as the location of the php file:
/.7/var/virtuals/tpg1/public_html/blog/stats/lgf-reflog-searchv2.php
that's a clue as to what the path needs to be. ie. /.7/var/virtuals/tpg1/public_html/blog/stats/….etc.
March 16th, 2003 at 6:52 am
Thanks Jennifer for your fast reply! This site rocks! (But you already knew that)
March 16th, 2003 at 7:16 am
Hmm, I installed it and everything seems fine (paths are okay), but all I get in the reflog-searchv2.txt file are little boxes (linebreaks?) and no info about searchterms what-so-ever.
Did I miss something?
http://www.flabber.nl/phpscripts/keywords/reflog-searchv2.txt
March 16th, 2003 at 8:12 am
Did you test going to to your site using a search engine referral? (also - you'll want to display the "show-ref" page to display the search keywords, etc.)
(Do you have a page on your site where you're testing this that's not quite…so offensive? My 2-year old daughter hangs out with me most of the time I'm online… your site isn't exactly "family oriented")
Also - do you have ALL the files uploaded? They need to be in the same directory as each other, and when I went to http://www.flabber.nl/phpscripts/keywords/lgf-reflog-searchv2.php I got a file not found. Version 2 is completely different and you'll need to upload *all* the files.
March 16th, 2003 at 9:13 am
Yes, I've tested it by refering from a searchpage ( http://www.google.nl/search?hl=nl&ie=utf-8&oe=utf-8&q=download+single+jamai&btng=google+zoeken&lr= third link, it'll lead to a less offensive page, sorry about that)
I reinstalled everything, thiss time keeping the names of the files exactly as in the zipfile of version 2. Still no luck. ( http://www.flabber.nl/phpscripts/keywords/show-refs-searchv2.php is empty)
The file "reflog-searchv2.txt" is being updated though! Everytime someone hits me via a searchengine, an asciisymbol is being added. It looks like this: http://www.flabber.nl/phpscripts/keywords/reflog.txt.jpg
March 16th, 2003 at 9:25 pm
Ok - found the bug and updated the script.
March 25th, 2003 at 11:34 am
I rewrote this script from the ground up and have a different display, which shows the search engine, and I also have the date and time displayed in the list.
It also uses one referrer file for search queries and non-search queries, and one reflog logging file.
Also had the kill referrer file I mentioned earlier.
Details
Example in sidebar
April 30th, 2003 at 9:25 pm
I know my paths are right. I can't get it to work. I've tried testing. I'm not getting any results.
May 22nd, 2003 at 4:47 am
Are you testing with http://www.google.com ?
Google isnt working I noticed. I had the same problems, then I tried yahoo.com and it worked fine!
Why doesnt google work?
May 22nd, 2003 at 6:40 am
Google's working just fine on the demos on scripty.
May 22nd, 2003 at 7:32 pm
not for me, anyone else having the problem or is it just me?
July 23rd, 2003 at 1:55 pm
I like to know somethings about the people who visit my site. Most of the people are lurkers and don't…
August 7th, 2003 at 10:00 pm
I've been getting this error:
Fatal error: Cannot redeclare extractkeywords3() (previously declared in /home/httpd/vhosts/littlelioness.net/httpdocs/lgfrefs/lgf-search-Functions.php:2) in /home/httpd/vhosts/littlelioness.net/httpdocs/lgfrefs/lgf-search-Functions.php on line 2
which doesn't really make sense to be as I thought that they were the same lines? Could it have something to do with me iuncluding the refs list in my sidebar? If so, is there a better waty to do that without including the show refs file?
August 20th, 2003 at 2:35 pm
Oh, and no more WeatherPixie.
October 22nd, 2003 at 12:59 pm
I am using your modified referrers script with no problems.
http://www.grabbingsand.com/referrers.php
However, the keyword referrers script is not cooperating. (Link to my page.)
Here is the error:
—- */ // Name of referrer log file $reflog = "/home/httpd/vhosts/grabbingsand.com/httpdocs/reflog-searchv2.txt"; include('/home/httpd/vhosts/grabbingsand.com/httpdocs/lgf-search-Functions.php'); ?>
Warning: file("") - Inappropriate ioctl for device in /home/httpd/vhosts/grabbingsand.com/httpdocs/keywords.php on line 30
Warning: Invalid argument supplied for foreach() in /home/httpd/vhosts/grabbingsand.com/httpdocs/keywords.php on line 32
Any ideas? Thank you.
October 22nd, 2003 at 1:06 pm
Nevermind. All clear now. Thanks.
December 10th, 2003 at 3:29 pm
Jenn:
thanks for the code; thought I followed it religiously but am getting the following "warning;"
Warning: main(/madskipp/public_html/cgi-bin/lgf-reflog-searchv2.php): failed to open stream: No such file or directory in /home/madskipp/public_html/index.html on line 491
Warning: main(): Failed opening '/madskipp/public_html/cgi-bin/lgf-reflog-searchv2.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/madskipp/public_html/index.html on line 491
December 10th, 2003 at 3:37 pm
I'm not sure, but based on the error message - it seems to be showing your paths two different ways:
/madskipp/public_html/cgi-bin/lgf-reflog-searchv2.php
(I assume this is what you put in for the path)
and this:
/home/madskipp/public_html/index.html
Do you see the difference? It may be that the error is misrepresenting what you have in your code - but if it isn't, your path is incorrect. You need to make sure the path you have specified in your file is /HOME/madskipp/public_html/cgi-bin/lgf-reflog-searchv2.php
January 17th, 2004 at 6:11 am
Sorry I'm late to the party the script works fine but how do I get it to show on my homepage instead of show-refs-searchv2.php? Please respond thanks
June 24th, 2004 at 2:01 pm
I have a couple of questions, but I'll ask them one at a time– in order of priority.
1. Where on my site do I place the files? Because when I place them at the core of my site (WWW.mysite.com/files) I get an error, BUT when I created a separate folder (www.mysite.com/[referrerlog]/files) for them inside the core I get no such errors. I don't see anything, but a blank page but I rather have that than an error, lol.
Does the location of the files matter at all? I mean in order for the files to detect the referrals…?
September 18th, 2004 at 9:34 pm
So I'm trying to figure out what the semaphore-search.ref file does. Obviously I didn't figure it out or I wouldn't be here…
Gary
September 18th, 2004 at 9:36 pm
So if I make sure this is on every page. All search results from all pages get dumped into the same file, right?
Thanks,
Gary
October 30th, 2004 at 7:22 am
Hi… thanks for this script, it's something I've been looking for for a while. But… what would be some possible reasons that this script would just return a blank page?