scriptygoddess RSS Feed
 
 
 
 

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.

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)

56 Responses to “Last 50 keyword referrers”

  1. 1
    Ain't too proud to blog:
    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…

  2. 2
    rickie beth:

    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.

  3. 3
    Richard Evans Lee:

    Wow, that was fast. Many, many thanks.

    Richard

  4. 4
    Computer Toaster:
    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…

  5. 5
    Babs:

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

  6. 6
    Babs:

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

  7. 7
    Lisa, Gal of Unix:

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

  8. 8
    Daisyhead:
    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

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

  10. 10
    rickie beth:

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

  11. 11
    Jennifer:

    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.

  12. 12
    rickie beth:

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

  13. 13
    rickie beth:

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

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

  14. 14
    Jennifer:

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

  15. 15
    Will:

    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?

  16. 16
    Jennifer:

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

  17. 17
    Jennifer:

    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"

  18. 18
    nancy:

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

  19. 19
    roe:

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

  20. 20
    Jennifer:

    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?

  21. 21
    roe:

    Actually, perfect sense. :) And many thanks!

  22. 22
    roe:

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

  23. 23
    Jennifer:

    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

  24. 24
    Gert:

    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!

  25. 25
    Gert:

    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!

  26. 26
    Jennifer:

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

  27. 27
    Jennifer:

    Version 2 has been added. :)

  28. 28
    Tim G:

    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

  29. 29
    Jennifer:

    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

  30. 30
    Jennifer:

    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…

  31. 31
    Tim G:

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

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

  32. 32
    Jennifer:

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

  33. 33
    Tim G:

    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?

  34. 34
    Jennifer:

    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.

  35. 35
    Gert:

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

  36. 36
    Gert:

    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

  37. 37
    Jennifer:

    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.

  38. 38
    Gert:

    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

  39. 39
    Jennifer:

    Ok - found the bug and updated the script.

  40. 40
    Ron:

    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

  41. 41
    Babs:

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

  42. 42
    Anonymous:

    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?

  43. 43
    Jennifer:

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

  44. 44
    Anonymous:

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

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

  46. 46
    Fiona:

    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?

  47. 47
    Live in the Delirious Cool:
    Things left behind.
    Oh, and no more WeatherPixie.

  48. 48
    Thomas:

    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.

  49. 49
    Thomas:

    Nevermind. All clear now. Thanks.

  50. 50
    Lew:

    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

  51. 51
    Jennifer:

    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

  52. 52
    Maurice Tanner:

    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

  53. 53
    Jessy:

    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. 54
    Gary LaPointe:

    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. 55
    Gary LaPointe:

    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. 56
    Alex:

    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?

Bookmarks

WordPress Resources

Meta