Thu August 28th 2008 10:07 am Blog | Gallery | Geek | Travels | Home | Contact | Archives | Links
Tux
Blog Gallery Geek Travels Home Contact Archives Links
MP3 Playlist Generator
MySQL: Get Next Auto_increment
PHP Fortune
Recurses! Foiled again....
Kernel Watch
Get yer PHP Referrers here

Geek : Get yer PHP Referrers here

Get yer PHP Referrers here
Friday April 5th, 2002

A note about this entry:
The script described below has changed since it was originally written, only because I have moved the whole site to a different server on a different platform. I'm still doing essentially the same thing, only now I'm using a Cold Fusion app instead of PHP, and the referral info is being stored in a DB instead of a text file. You can see it here.

ANOTHER note about this entry:
Once again, the site has been rebuilt, only this time we're using PHP. Still using a ported version of the CF database referral script mentioned above.

In my travels around the www, I have seen a number of nifty little referral tools, but none of them were of any use to me. Either the source was not made available, or it was database-driven, or it was just plain BAD. So, since my weblogs don't contain human-readable referral info, I decided to take matters into my own hands, and come up with exactly what I needed -- something that:

1. gets referrer data from all visitors to my index page,
2. stores the data in a flat file (I have no DB),
3. filters out my domain name (I don't care about self-referrals),
4. ignores empties (links from emails and such),
5. displays the last X number of those referrers

and now, the code:

The first snippet (Example 1) does the tasks of fetching, filtering and storing the $HTTP_REFERER (along with the date and time of visit).

Example 2 does the following:

(1) assigns a variable name, $tail, to the 'tail' system command. (Tail is a UNIX/Linux executable that outputs text from the bottom up, i.e. in descending order. Check your version to see if and where it's installed by typing 'which tail' at the console.)
(2) displays the value of the variable $tail.

OH BUT THEN --

Of course I had to put anchor tags around those URLs so people could click em. So the 2 lines in Example 2 became Example 3.

See it in action

Interested in this subject?
Read more:

waxy.org
iawiki.net
oreillynet.com
disenchanted.com
decafbad.com

EXAMPLE 1: EXAMPLE 2: EXAMPLE 3:
Posted by Jamie
Comments: 9
Next Entry

Comments: (9)

Hmmmm. Very interesting, whatever it is. Greek? Aramaic? Klingon?

Posted by Kev on 5/15/02 at 1:19 PM EST

it's geek-speak my friend!

Posted by Busta on 6/1/02 at 7:14 PM EST

Hmmm Something wrong, that last example doesnt seem to work, shows up as empties. ie:

-[]
-[]
?

Posted by Bob on 7/7/02 at 12:30 PM EST

What do you mean?
You tried putting this code on your site?
Make sure you edit any paths so that they match yours. And you might need to fix the RegEx to match whatever is actually in your referrer log -- for example, each entry in my log starts with "http://", so the 'foreach' loop spits out only lines that start with that, and then wraps them in anchor tags. maybe yours are different. try commenting out or getting rid of the whole foreach {} loop. that should simply spit out the last 50 lines of your log file regardless. also, make sure that the log file exists and is getting read by the script.
by the way, i hope you come back to actually read this comment, because you didnt leave you email. you put in mine! if you left me yours i could have replied to you directly.

Posted by Jamie on 7/7/02 at 1:04 PM EST

interesting, fixed it, much love, cheers.

Posted by Bob on 7/7/02 at 11:34 PM EST

yah too bad coldfusion is b00000ty
your former skript was much better

Posted by maynard g krebbs on 10/16/02 at 6:03 PM EST

Very cool and interesting stuff here, need some time to get mt head round it all..Keep up the good work.

Posted by surf on 6/4/03 at 10:37 AM EST

Good Site!

Posted by Rick on 4/2/07 at 11:37 PM EST

Good Site!

Posted by Guruchel on 4/3/07 at 6:43 PM EST


Your 2¢ (comments subject to approval)
The Captcha image Phonetic spelling (mp3)
© 2003 Jamie Doris Blog | Gallery | Geek | Travels | Home | Contact | Archives | Links