scriptygoddess

18 Jan, 2003

Last 50 keyword referrers

Posted by: Jennifer In: Scripts

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.

Download it 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)

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

56 Responses to "Last 50 keyword referrers"

1 | Live in the Delirious Cool

August 20th, 2003 at 2:35 pm

Avatar

Things left behind.
Oh, and no more WeatherPixie.

2 | The Trommetter Times

July 23rd, 2003 at 1:55 pm

Avatar

Site Statistics
I like to know somethings about the people who visit my site. Most of the people are lurkers and don't…

3 | Daisyhead

January 26th, 2003 at 3:04 pm

Avatar

Sunday to do list
It's been a while since I've posted a "To Do" list, but since they really do seem to help keep

4 | Daisyhead

January 26th, 2003 at 9:40 pm

Avatar

Something's different
I did a few tweaks around the site tonight. I added the last 50 keyword referrers script to the stats

5 | Ain't too proud to blog

January 19th, 2003 at 4:49 am

Avatar

Potpourri for $400, Alex
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…

6 | Computer Toaster

January 19th, 2003 at 12:08 pm

Avatar

Scrippty Goddess: last 50 keyword referrers
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…

7 | Maurice Tanner

January 17th, 2004 at 6:11 am

Avatar

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

8 | Jennifer

December 10th, 2003 at 3:37 pm

Avatar

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

9 | Thomas

October 22nd, 2003 at 1:06 pm

Avatar

Nevermind. All clear now. Thanks.

10 | Lew

December 10th, 2003 at 3:29 pm

Avatar

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

11 | Thomas

October 22nd, 2003 at 12:59 pm

Avatar

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.

12 | Fiona

August 7th, 2003 at 10:00 pm

Avatar

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?

13 | Jennifer

May 22nd, 2003 at 6:40 am

Avatar

Google's working just fine on the demos on scripty.

14 | Anonymous

May 22nd, 2003 at 7:32 pm

Avatar

not for me, anyone else having the problem or is it just me?

15 | Babs

April 30th, 2003 at 9:25 pm

Avatar

I know my paths are right. I can't get it to work. I've tried testing. I'm not getting any results.

16 | Anonymous

May 22nd, 2003 at 4:47 am

Avatar

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?

17 | Ron

March 25th, 2003 at 11:34 am

Avatar

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

18 | Jennifer

March 16th, 2003 at 9:25 pm

Avatar

Ok – found the bug and updated the script.

19 | Gert

March 16th, 2003 at 9:13 am

Avatar

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

20 | Gert

March 16th, 2003 at 7:16 am

Avatar

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

21 | Jennifer

March 16th, 2003 at 8:12 am

Avatar

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.

22 | Jennifer

March 14th, 2003 at 4:59 pm

Avatar

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.

23 | Gert

March 16th, 2003 at 6:52 am

Avatar

Thanks Jennifer for your fast reply! This site rocks! (But you already knew that)

24 | Jennifer

March 12th, 2003 at 1:15 pm

Avatar

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 :)

25 | Tim G

March 14th, 2003 at 1:46 pm

Avatar

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?

26 | Tim G

March 12th, 2003 at 1:10 pm

Avatar

ok I'll use the server paths…that wasn't clear to me.

where is function.php? didn't see it in the zip.

27 | Jennifer

March 12th, 2003 at 12:29 pm

Avatar

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

28 | Jennifer

March 12th, 2003 at 12:33 pm

Avatar

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…

29 | Tim G

March 12th, 2003 at 12:12 pm

Avatar

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

30 | Jennifer

March 11th, 2003 at 11:09 am

Avatar

Version 2 has been added. :)

31 | Jennifer

March 11th, 2003 at 10:46 am

Avatar

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" ;-)

32 | Gert

March 10th, 2003 at 2:22 pm

Avatar

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!

33 | Gert

March 10th, 2003 at 3:09 pm

Avatar

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!

34 | Jennifer

March 4th, 2003 at 2:23 pm

Avatar

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

35 | roe

February 9th, 2003 at 12:12 am

Avatar

Actually, perfect sense. :) And many thanks!

36 | roe

March 4th, 2003 at 2:03 pm

Avatar

: 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!

37 | Jennifer

February 8th, 2003 at 7:29 am

Avatar

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?

38 | roe

February 8th, 2003 at 4:03 am

Avatar

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! :)

39 | nancy

February 2nd, 2003 at 3:45 pm

Avatar

is there any way to link up the search keywords with the referring url?

40 | Jennifer

January 31st, 2003 at 3:35 pm

Avatar

Will – that script (the original 50 referrers script) was written by little green footballs – he has the download there on his site….

41 | Jennifer

January 31st, 2003 at 3:38 pm

Avatar

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"

42 | Jennifer

January 28th, 2003 at 10:24 pm

Avatar

Cool! I'm glad I could help (put in you the right direction at least) :D

I like your solution :)

43 | Will

January 31st, 2003 at 3:19 pm

Avatar

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?

44 | rickie beth

January 28th, 2003 at 10:15 pm

Avatar

Blech, in my haste I forgot to convert the brackets to ascii…

$rtwo = str_replace(":", "<br>", $r);
echo(str_replace("/", "<br>", $rtwo));

45 | rickie beth

January 28th, 2003 at 10:14 pm

Avatar

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. :)

46 | rickie beth

January 28th, 2003 at 5:07 pm

Avatar

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. :)

47 | Jennifer

January 28th, 2003 at 8:17 pm

Avatar

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.

48 | Babs

January 19th, 2003 at 11:57 pm

Avatar

scratch that. it works. a series of my stupidity. Forgetting to put the leading / and including the wrong file *doh!*

49 | Lisa, Gal of Unix

January 21st, 2003 at 11:31 pm

Avatar

I installed this and discovered that most people don't find me by searching. :) It's still a fun addition.

50 | rickie beth

January 19th, 2003 at 11:38 am

Avatar

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.

51 | Richard Evans Lee

January 19th, 2003 at 12:07 pm

Avatar

Wow, that was fast. Many, many thanks.

Richard

52 | Babs

January 19th, 2003 at 11:36 pm

Avatar

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….

53 | Jessy

June 24th, 2004 at 2:01 pm

Avatar

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…?

54 | Gary LaPointe

September 18th, 2004 at 9:34 pm

Avatar

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

55 | Gary LaPointe

September 18th, 2004 at 9:36 pm

Avatar

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

56 | Alex

October 30th, 2004 at 7:22 am

Avatar

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?

Featured Sponsors

About


Advertisements