Tracking entry referrers with PHP in MT

I’ve always wanted to track referrers for each entry and at the same time be able to tell which entries are the more popular ones by keeping track of each entry’s hit count.

So I did the smart thing first by Googling to see if anyone else had done it. I found the AWStatsReferers MT plugin at the MT Plugin Directory but it requires your host to have AWStats installed. My host doesn’t, and I wasn’t going to get them to install AWStats just so I can track referrers for my blog. Refer is a referrer tracking script that turned up - it actually seems like it could do what I wanted with a little tweaking, but a look at the code left me thinking there should be a simpler way to achieve my more specific goals (i.e. track referers and, consequently, hit count for each entry).

So, hey, I decided to whip up a simple hack of sorts using PHP and a database table to store the referrers.


Tracking entry referrers with PHP in MT

Requirements: MovableType, webhost that supports PHP, database (MySQL in this tutorial)

A plain text version of this tutorial is also available here.

  1. First off, any page where you wish to display the referrers or hit count, including your archives and main index page, need to have a .php extension (or any other extension that will cause the file to be pre-processed by PHP). You can do so by renaming your Archive File Templates to have a .php extension (go to Weblog Config -> Archiving). The same goes for your main index page (go to Templates) .
  2. Create the database table. The SQL is:

    CREATE TABLE `mt_entryhits` (
    `entry_id` INT(11) NOT NULL
    REFERENCES mt_entry(entry_id)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
    `referer` VARCHAR(255) NOT NULL
    );

    You can use either phpMyAdmin, the MySQL command-line client or whatever suits your boat.

  3. Create a file named db-config.php with the following code:

    <?php
    $host = ‘host’; // database server hostname
    $user = ‘user’; // database username
    $password = ‘password’; // database password
    $database = ‘database’; // MT database
    ?>

    Replace the values of the variables as per your configuration. Upload it in your blog’s top level directory (i.e. the Local Site Path of your weblog, as specified in the Weblog Configuration screen).

  4. Login to your MovableType installation and Manage your weblog. Go to Manage -> Templates -> Archive-Related Templates -> Individual Entry Archive.
  5. At the top of the template, add the following lines:

    <?php
    error_reporting(0);

    include( ‘<$MTBlogSitePath$>db-config.php’ );

    mysql_connect( $host, $user, $password );
    mysql_select_db( $database );

    // this is the list of referrers you don’t want to record
    // use the following format within the parentheses:
    // ‘http://domain1.com’, ‘http://domain2.com’, …
    // leave it blank if you want to record all referrers
    $ignore_list = array( ‘http://referrer.you.want.to.ignore’ );

    // check referrer string to determine if we want to record it
    $ignore_referrer = false;
    foreach( $ignore_list as $ignore ) {
    if( stristr( $_SERVER[’HTTP_REFERER’], $ignore ) !== false ) {
    $ignore_referrer = true;
    break;
    }
    }

    // record the referer
    if( !$ignore_referrer ) {
    mysql_query( “INSERT INTO mt_entryhits(entry_id, referer) VALUES (<$MTEntryID$>, ‘{$_SERVER[’HTTP_REFERER’]}’)” );
    }

    // get the no. of times this entry has been read
    $rs = mysql_query( ‘SELECT COUNT(*) FROM mt_entryhits WHERE entry_id=<$MTEntryID$>’ );
    $row = mysql_fetch_row( $rs );
    $hits = $row[0];

    // get the list of referers
    $sql =
    ‘SELECT referer, COUNT(*) AS count
    FROM mt_entryhits
    WHERE entry_id=<$MTEntryID$>
    GROUP BY referer
    ORDER BY count DESC’;

    $rs = mysql_query( $sql );
    ?>

    This code snippet is specific to MySQL - you should be able to change it easily for PostgreSQL or SQLite (if not, let me know and I’ll post code snippets for those RDBMSs too). Of course, you can plug in a database abstraction library like the excellent ADODB, but I leave out that portable solution in favor of database-specific built-in function calls because MovableType supports only MySQL, PostgreSQL, or SQLite.

  6. In the same template (the Individual Entry Archive template), look for a good place to display the entry hit count and insert the following code:

    Read <?=$hits?> time<?php if($hits != 1) echo ’s’;?>

    I place them in the “Posted by” bit at the end of each entry, which for the default MT template is

    <span class=”posted”>Posted by <$MTEntryAuthor$> at <$MTEntryDate$>
    <MTEntryIfAllowPings>
    | <a href=”<$MTCGIPath$><$MTTrackbackScript$>?__mode=view&entry_id=<$MTEntryID$>” onclick=”OpenTrackback(this.href); return false”>TrackBack</a>
    </MTEntryIfAllowPings>
    | Read <?=$hits?> time<?php if($hits != 1) echo ’s’;?>
    <br /></span>
  7. Now, it’s time to display the referrers. Again in the same template, add the following code where you wish to display the referrers.

    <?php
    // display the list of referers
    echo ‘<div class=”sidetitle”>Referrers</div>’, “\n”;
    echo ‘<div class=”side”>’, “\n”;
    echo ‘<ul>’, “\n”;
    while( $row = mysql_fetch_assoc( $rs ) ) {

    $referer = $row[’referer’];
    $count = $row[’count’];

    echo ‘<li>’;

    if( strpos( $referer, ‘http://’ ) !== false ) {
    echo ‘<a href=”‘, $referer, ‘” target=”_blank”>’;

    // truncate URL if too long
    if( strlen($referer) > 90 ) {
    $referer = substr($referer, 0, 90) . ‘…’;
    }
    echo $referer, ‘(’, $count, ‘)’;
    echo ‘</a>’;
    }
    else {
    // truncate URL if too long
    if( strlen($referer) > 90 ) {
    $referer = substr($referer, 0, 90) . ‘…’;
    }

    // handle cases where there is no referrer
    if( $referer == ” ) {
    $referer = ‘Direct hit or unknown referrer’;
    }
    echo $referer, ‘(’, $count, ‘)’;
    }
    echo ‘</li>’;
    echo “\n”;
    }
    echo “\n”;
    echo ‘</ul>’, “\n”;
    echo ‘</div>’;
    ?>

    You can format the HTML to suit your current template.

  8. Phew! The hardest part is now over. All that’s left is to display the number of times each entry has been read in the other archive pages and the main page (Main Index). I’ll only work through the changes to the Main Index template, since it will be similar for the other templates (Category Archive, Date-Based Archive, any other templates you have created that displays blog entries).

    At the top of the template, add the following lines:

    <?php
    error_reporting(0);

    include( ‘<$MTBlogSitePath$>db-config.php’ );

    mysql_connect( $host, $user, $password );
    mysql_select_db( $database );
    ?>

    Look for the <MTEntries> tag in the template and add the following lines after it:

    <?php
    // get the no. of times this entry has been read
    $rs = mysql_query( ‘SELECT COUNT(*) FROM mt_entryhits WHERE entry_id=<$MTEntryID$>’ );
    $row = mysql_fetch_row( $rs );
    $hits = $row[0];
    ?>

    Now that we’ve the number of hits in the variable $hits, we can display the entry hit count as before by adding the following line of code within the <MTEntries> tag:

    Read <?=$hits?> time<?php if($hits != 1) echo ’s’;?>
  9. Do the same for the other archive templates (Category Archive, Date-Based Archive, any other templates you have created that displays blog entries).
  10. Rebuild your site and you’re done!

Thanks to everyone who gave comments and asked questions at the MovableType support forums and elsewhere, who pointed out things I overlooked.

Update: Matt Moore has an alternative (based on this very post! ;-)) that includes collection of the page title of the referrer, and also the search terms used to get to your blog entry. Check out his entry entitled “How to collect referrer data

81 Comments & TrackBacks ()

Paper doll icon
lovelinks's Gravatar

entry referrers
redemption in a blog: Tracking entry referrers with PHP in MT - uses MySQL database, and looks much more elegant…

Posted by: lovelinks on August 17, 2003 8pm

Paper doll icon
Paul Scrivens's Gravatar

Great article. I will definitely have to implement this some time.

Posted by: Paul Scrivens on August 18, 2003 4am

Paper doll icon
kadyellebee's Gravatar

linkyness
I’m finding such good links while catching up on news reads that I just had to share some of them….

Posted by: kadyellebee on August 18, 2003 6am

Paper doll icon
sam's Gravatar

hi, I’m trying to set this up but can’t seem to get it working
I think my problem may be in the db-config.php

what host is this referring to?

$host = ‘host’;

Posted by: sam on August 18, 2003 4pm

Paper doll icon
Cheah Chu Yeow's Gravatar

Sorry I wasn’t a bit more clear. That’s your database host name (check with your webhosting service provider if uncertain). In most cases it will be ‘localhost’, though not always.

Thanks for letting me know - I’ll go edit the entry to explain the variables a bit.

Posted by: Cheah Chu Yeow on August 18, 2003 4pm

Paper doll icon
sam's Gravatar

aha!
thanks so much!
works great now
great job!
-sam

Posted by: sam on August 18, 2003 4pm

Paper doll icon
Ryan's Gravatar

I’ve followed the directions, but nothing is happening, database-wise. Perhaps I didn’t get all of the code? Safari is making those text areas too small (especially for the one-liners.)

Posted by: Ryan on August 18, 2003 6pm

Paper doll icon
maraboutslim's Gravatar

hi, can you expand on this part. i’m not getting it. What do I enter to rename the files .php?

“First off, any page where you wish to display the referrers or hit count, including your archives and main index page, need to have a .php extension (or any other extension that will cause the file to be pre-processed by PHP). You can do so by renaming your Archive File Templates to have a .php extension (go to Weblog Config -> Archiving). The same goes for your main index page (go to Templates) . ”

thanks,

slim

Posted by: maraboutslim on August 18, 2003 10pm

Paper doll icon
maraboutslim's Gravatar

never mind! i think i’ve found it. configuration/preferences. thanks.

Posted by: maraboutslim on August 18, 2003 11pm

Paper doll icon
Links's Gravatar

http://ko.offroadpakistan.com/links/cat_mt.html#000481
Tracking entry referrers with PHP in MT…

Posted by: Links on August 19, 2003 12am

Paper doll icon
KO's Gravatar

I am already using the Refer script. Can I use both at the same time, or should I delete the refer script first before?

Also, can the number of referrers saved in the db be limited?

Posted by: KO on August 19, 2003 12am

Paper doll icon
Ryan's Gravatar

I am also using the Refer script. Perhaps the referrals are being eaten by that script. Just a wild guess.

Posted by: Ryan on August 19, 2003 3am

Paper doll icon
Considering...'s Gravatar

A better wheel. Maybe.
Today, I tried to install a bit of support for tracking entry referrers. As you can see, I haven’t had much luck getting it to work. I’ll probably undo that work in a little while unless I find out how…

Posted by: Considering... on August 19, 2003 3am

Paper doll icon
Christian's Gravatar

If you want to limit the number of referers stored in the db this should work (untested)

redemption: maybe a small suggestion: Instead of counting inside the while loop try using count() and group by.

$rs = mysql_query( 'SELECT referer, COUNT(*)
FROM mt_entryhits WHERE entry_id=<$MTEntryID$>
GROUP BY referer' );

Posted by: Christian on August 19, 2003 11am

Paper doll icon
Christian's Gravatar

Hm, the empty box wasn’t enty when I preview. Anyways, here it is again.

Replacement of step 5 “At the top of the template, add the following lines:”

 

Posted by: Christian on August 19, 2003 11am

Paper doll icon
Cheah Chu Yeow's Gravatar

KO: following Christian’s suggestion should allow you to limit the no. of referrers stored.

Ryan: I’ve had someone with the same problem too. I’ll look into her’s and get back to you - maybe I forgot something. Sorry about the collapsed divs - I’ve been trying to figure out a good way of displaying the code without the text overflowing into out of the div. Apparently there is still some more work to be done.

Christian: Thanks for your suggestion on using GROUP BY! I’ve implemented your suggestion in the tutorial. And thanks for being my ‘tech support’ ;).

Posted by: Cheah Chu Yeow on August 19, 2003 12pm

Paper doll icon
Cheah Chu Yeow's Gravatar

Ryan: Oh yes one more thing - if you can’t see the code very well in Safari, there is a text version “here”:http://blog.codefront.net/archives/2003/08/16/tracking_entry_referrers_with_php_in_mt.txt. (link is also available above). At least until I find a good way to display long lines of code without overflowing.

Posted by: Cheah Chu Yeow on August 19, 2003 12pm

Paper doll icon
Christian Sobetzko's Gravatar

redemption: No problem. Could you edit my comment from August 19, 2003 11:14 AM because <$MTEntryID$> has been removed and the query will not work.

This is the line:

$rs = mysql_query( 'SELECT referer, COUNT(*) FROM mt_entryhits WHERE entry_id= GROUP BY referer' );

entry_id is missing the MTEntryID thing.

Posted by: Christian Sobetzko on August 19, 2003 1pm

Paper doll icon
Cheah Chu Yeow's Gravatar

Christian: I’ve edited it. Thanks again.

Posted by: Cheah Chu Yeow on August 19, 2003 1pm

Paper doll icon
Ryan's Gravatar

Thanks for the text link. I was going to try that before waiting to see what happens. There were a few missing “php echo” bits, but nothing, it seems, that changed the fact that referrals aren’t being recorded in mt_entryhits. I’ll wait a bit longer.

Posted by: Ryan on August 19, 2003 3pm

Paper doll icon
unchained thoughts's Gravatar

focus
Thank you for everyone’s thoughtful and helpful suggestions about my wedding woes. I am feeling better about it now, trying to think about what we want and I will reconcile the whole dress thing in the months to come. Much…

Posted by: unchained thoughts on August 19, 2003 4pm

Paper doll icon
Cheah Chu Yeow's Gravatar

Thanks to “Sam”:http://www.lollygagger.org/stb/plog and to “Jane”:http://www.unchainedthoughts.com/, who both managed to get it working for communicating with me their experiences.

There seems to be no problems with the code (though the instructions probably need to be worked over to be easier to understand).

I’ve a few suggestions for those of you (including Ryan) who couldn’t yet get it to work.

* make sure your files are .php files and you’ve rebuilt
* make sure you’ve the host, user, password and database specified correctly in db-config.php

Posted by: Cheah Chu Yeow on August 19, 2003 5pm

Paper doll icon
Live in the Delirious Cool's Gravatar

Posted elswhere, counted here.
Two more excellent advanced widgets for tracking what’s said and seen here and elswhere - and a plug for my favorite webring.

Posted by: Live in the Delirious Cool on August 22, 2003 2am

Paper doll icon
scriptygoddess.com's Gravatar

Referrer script and entry hit tracker
Donna posted a few neat little tidbitds - but the one I was most interested in was the referrer script that also tracks hits on an entry… Like “read 100 times” etc. Here’s the script from redemption in a blog….

Posted by: scriptygoddess.com on August 22, 2003 1pm

Paper doll icon
Peter Bowyer's Gravatar

Nice work. What would be nice is a MT plugin to do the above - then it will work without the need for PHP to interpret the pages. Meaning you could expand this to work with all pages on the site, not just articles.

Pluse, using the built-in database connection the code will be the same for all supported databases.

Posted by: Peter Bowyer on August 24, 2003 5pm

Paper doll icon
kiesows.de's Gravatar

referrers
meiner einer hatte mal wieder lust etwas am blog zu verändern, und da ich neulich über Tracking entry referrers with…

Posted by: kiesows.de on August 27, 2003 12am

Paper doll icon
Pinging Knight's Gravatar

Minor Blog Update
Made a few minor updates to the design and workings of my blog: Comments are now numbered. Your email will…

Posted by: Pinging Knight on August 27, 2003 10pm

Paper doll icon
Sasha's Gravatar

I really love this script, it works like a charm!
I just noticed, you can’t use this for more than one blog in the same database, right? I mean, I’d have to edit the table names and stuff. Maybe a suggestion for the next version to build this one? It would not be very hard, I imagine, to add the blogID to each refer as well? :) Great job on this though!!

Posted by: Sasha on August 30, 2003 5pm

Paper doll icon
Cheah Chu Yeow's Gravatar

Hi Sasha. Glad you find it useful.

I think it actually works for more than one blog in the same database, since MT keeps the entry IDs of blogs unique across all blogs in a MT setup.

Just do the same (meaning changing the templates as I’ve written) for all other blogs and it should work fine. You can skip the steps of creating the database table (mt_entryhits).

Posted by: Cheah Chu Yeow on August 30, 2003 5pm

Paper doll icon
Cookie Crumbs's Gravatar

Tracking entry referrers with PHP in MT
Tracking entry referrers with PHP in MT Want to know who is coming to see your entries? Track them!…

Posted by: Cookie Crumbs on August 31, 2003 2am

Paper doll icon
Les's Gravatar

I was having trouble getting this to work as well as it wasn’t putting any data into my database either. Looking at the code more closely I discovered the reason why. I host more than one weblog at my site and all of them have different domain names than where I store my MT script. As a result the use of $MTBlogSitePath$ in the Include results in the script not finding my db-config.php file. Instead, you should modify the script to use $MTCGIPath$ in all the Include statements so it knows the proper place the find the file.

Posted by: Les on September 2, 2003 10pm

Paper doll icon
Les's Gravatar

Of course, now I’m getting a completely different error:

Warning: main(): stream does not support seeking in /home/les/public_html/seb/archives/2003/09/02/ toyotas_newest_prius_parks_itself.php on line 3

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/les/public_html/seb/archives/2003/09/02/ toyotas_newest_prius_parks_itself.php on line 13

Posted by: Les on September 2, 2003 10pm

Paper doll icon
aman's Gravatar

in pace 2 , you said: “Create the database table…you can use either phpMyAdmin, the MySQL command-line client or whatever suits your boat”.

But,my Q is: how can i use that codes in Mysql, in the other hand, how can i creat the database table in mysql?

Posted by: aman on September 5, 2003 9pm

Paper doll icon
Cheah Chu Yeow's Gravatar

Les: I realise now my mistake and have updated the entry. You shoulld keep it as <$MTBlogSitePath$> but upload db-config.php to your blog’s local site path instead (same directory as your blog’s index page).

aman: If you have phpMyAdmin, you can run create the database if you cut-n-paste the SQL and run the SQL. Otherwise, if you can get shell access (telnet or SSH), run _mysql_ and input the SQL.

Posted by: Cheah Chu Yeow on September 6, 2003 7am

Paper doll icon
Geeky Bookmarks's Gravatar

Tracking entry referrers with PHP in MT
redemption in a blog: Tracking entry referrers with PHP in MT via Christine’s Cookie Crumbs…

Posted by: Geeky Bookmarks on September 6, 2003 9am

Paper doll icon
JayAllen - The Daily Journey's Gravatar

Tracking entry referrers in MT

Posted by: JayAllen - The Daily Journey on September 6, 2003 5pm

Paper doll icon
The Blog of the Century of the Week's Gravatar

Changing some scripts
I’m junking a bunch of CGI scripts and going to PHP. I’m doing this because it’s much easier to put PHP data in a page, since you just set your variables at the top and then you can call them…

Posted by: The Blog of the Century of the Week on September 14, 2003 3am

Paper doll icon
The Blog of the Century of the Week's Gravatar

PHP and MySQL: How to collect referrer data
Ok, here’s a special interest post: How to collect and display data on referrers, search terms, and number of reads on an individual post basis. You’ll need PHP, a MySQL database, and enough patience to work with your templates a…

Posted by: The Blog of the Century of the Week on September 21, 2003 8pm

Paper doll icon
//gtmcknight's Gravatar

Random Updates…
First, and foremost Radiohead was one of the best concerts I’ve ever been to. They are simply amazing, and the outdoor amphitheatre made it alot of fun as well. Thom Yorke’s performance was moving, funny, exciting, and hypnotic all at…

Posted by: //gtmcknight on October 6, 2003 5am

Paper doll icon
meowy's Got Stuff to Say's Gravatar

Counts! Project for tomorrow
Yay! Thanks to Violet at the MT forums, I think I’ve got just what I need. :) Her site is…

Posted by: meowy's Got Stuff to Say on October 20, 2003 6am

Paper doll icon
distant, early morning's Gravatar

Entry hit counter and referrers
I was asking about some stuff over on the movable type support forums, which a wonderful gal named Violet answered. Because she was so helpful I was curious and popped over to her weblog. I noticed that she had hit…

Posted by: distant, early morning on October 26, 2003 6pm

Paper doll icon
lisa's Gravatar

Hey,

I was wondering - is it possible to make this ignore all hits from a certain ip? I’d like to be able to check referrers etc without running up hit counts…

-Lisa

Posted by: lisa on October 26, 2003 9pm

Paper doll icon
Cheah Chu Yeow's Gravatar

Hi lisa, you may want to take a look at Matt Moore’s How to collect referrer data blog entry.

I’ve been too lazy to include instructions on how to exclude specified referrers, but if you want, I will do so.

Posted by: Cheah Chu Yeow on October 27, 2003 5am

Paper doll icon
Cheah Chu Yeow's Gravatar

I’ve updated the instructions to allow ignoring of specific referrers from being tracked. Check out the code comments in point 5 for more details.

It shouldn’t break any existing installations, but in the event that it does, do let me know.

Posted by: Cheah Chu Yeow on November 7, 2003 12am

Paper doll icon
highlyoverrated.info - do you need more?'s Gravatar

mt resources, die x-te
für mt gibt es alles und das auch noch tonnenweise ;) und das ist genial so: redemption in a blog…

Posted by: highlyoverrated.info - do you need more? on November 9, 2003 7am

Paper doll icon
craig1972's Gravatar

Hi, does this plugin require my pages to have a PHP extension?

Posted by: craig1972 on November 13, 2003 2pm

Paper doll icon
Cheah Chu Yeow's Gravatar

Yup it does, unless you configure your server to treat any other extensions
to be parsed as PHP files. Then, you can use that extension.

Posted by: Cheah Chu Yeow on November 14, 2003 12am

Paper doll icon
brad's Gravatar

if you want a quick and dirty way of seeing the stats without running up counts. stick “this php script”:http://www.thatbradguy.com/downloads/log.txt in your blog root (the same place you put the db-config.php file). change the filename to .php.

it will list your entries (with title) that have been read in the order of most popular to least popular with the number of times they have been read beside them. then below it will display each entries referers.

note: in order to keep up with the stats on my home page i changed the php code in step 5. on my homepage *only* i changed line 26. i replaced with 0 (zero). that way when it lists them in this log it has an “entry_id” for the home page. you could do this with any other page on your site as well, so long as you keep the numbers unique and make sure you don’t have a blog entry with the same number.

if you do this to any other page you’ll have to hack my script on lines 26-32 to reflect what you’ve done. the “entry_id” of 0 is already setup to display “Homepage” as its title.

Posted by: brad on November 20, 2003 3pm

Paper doll icon
brad's Gravatar

the code didn’t show up…

on line 26 i changed <$MTEntryID$> to 0 (zero)

also, you’ll have to “view source” or “save as” in order to get the code.

Posted by: brad on November 20, 2003 3pm

Paper doll icon
Fembat.Net :: Journal's Gravatar

MT Individual Entry Referrals
I’ve always wanted a more precise method of tracking referrers for each entry, and finally after months of trying to come up with something myself I finally fell upon a terrific MT Hack at redemption in a blog. This also…

Posted by: Fembat.Net :: Journal on November 24, 2003 9pm

Paper doll icon
Karen's Gravatar

I have been wanting to implement this for a while now, but I have no idea how to do any MySQL-related stuff. I’m also on a Mac and have no idea what command line is.

Is there an easier way to do this?

Posted by: Karen on December 28, 2003 3pm

Paper doll icon
Gregz's Gravatar

I’ve got me a little catch 22 problem here. For obvious reasons I want to ignore my own site as referer, but when I put it in the ignore array it stops counting as well. Would it not be more elegant to ignore them when displaying?

Posted by: Gregz on January 7, 2004 7pm

Paper doll icon
Carin's Gravatar

THis is exactly what I neded

Posted by: Carin on January 30, 2004 6pm

Paper doll icon
carlo's Gravatar

lovely css page, very impressive. wow :)

Posted by: carlo on February 16, 2004 8pm

Paper doll icon
pixelgraphix's Gravatar

Ressourcen für Movable Type
Wer auf der Suche nach einem Publishing-System für die eigene Internet-Präsenz ist, stößt früher oder später auf Movable Type. Ein Programm, das von Six Apart vor allem als Weblog-Werkzeug entwickelt und unterstützt …

Posted by: pixelgraphix on March 7, 2004 2am

Paper doll icon
Manuela's Gravatar

I absolutely love this solution and it works great. However, there is a validation problem. Some referrer URLs display special characters that need encoding. I have tried the textile plugin but did not get it to work on this issue. Maybe someone could help?

Posted by: Manuela on March 20, 2004 11pm

Paper doll icon
pixelgraphix's Gravatar

Und sie validieren doch
Auf pixelgraphix verwende ich die Referrer und Hits Zählung, die von Cheah Chu Yeow auf redemption in a blog veröffentlicht wurde. Durch die Anzeige der Referrer und der in ihnen enthaltenen Sonderzeichen fielen die entsprechenden Seiten beim…

Posted by: pixelgraphix on March 23, 2004 2am

Paper doll icon
pixelgraphix's Gravatar

Und sie validieren doch
Auf pixelgraphix verwende ich die Referrer und Hits Zählung, die von Cheah Chu Yeow auf redemption in a blog veröffentlicht wurde. Durch die Anzeige der Referrer und der in ihnen enthaltenen Sonderzeichen fielen die entsprechenden Seiten beim…

Posted by: pixelgraphix on March 23, 2004 2am

Paper doll icon
pixelgraphix's Gravatar

Und sie validieren doch
Auf pixelgraphix verwende ich die Referrer und Hits Zählung, die von Cheah Chu Yeow auf redemption in a blog veröffentlicht wurde. Durch die Anzeige der Referrer und der in ihnen enthaltenen Sonderzeichen fielen die entsprechenden Seiten beim…

Posted by: pixelgraphix on March 23, 2004 3am

Paper doll icon
pixelgraphix's Gravatar

Und sie validieren doch
Auf pixelgraphix verwende ich die Referrer und Hits Zählung, die von Cheah Chu Yeow auf redemption in a blog veröffentlicht wurde. Durch die Anzeige der Referrer und der in ihnen enthaltenen Sonderzeichen fielen die entsprechenden Seiten beim…

Posted by: pixelgraphix on March 23, 2004 9pm

Paper doll icon
shirtrat(dot)net's Gravatar

A few site changes
Long time no post. It’s been almost two weeks. Haven’t had much to say actually. Been working behind the scenes on a few things with my blog. I added a referrer to the bottom of each individual entry so you…

Posted by: shirtrat(dot)net on March 24, 2004 7am

Paper doll icon
iced glare's Gravatar

can you also use this script to show the top hits to entry? Like in the sidebar?

Posted by: iced glare on April 6, 2004 10am

Paper doll icon
Cheah Chu Yeow's Gravatar

can you also use this script to show the top hits to entry?

Theoretically, you could, but I can’t figure out how to figure out the permalink to an entry with just the entry ID.

Posted by: Cheah Chu Yeow on April 6, 2004 8pm

Paper doll icon
Chris's Gravatar

Hi, thank you very much for this tutorial, it is really great. Unfortunately it isn’t working 100% on my site, like you can see here at the bottom of the page: http://www.digitalvoodoo.de/singapur_hongkong/archives/vorbereitungen/lonely_planet_south_east_asia_thailand_malaysia.php

The Hit-count for each entry is working but the referrer list won’t work. Any idea what might be the problem?

It would be great if you get back to me :-)

Cheers,

Chris

Posted by: Chris on May 22, 2004 10am

Paper doll icon
Chris's Gravatar

Anybody out there who might help me?

Posted by: Chris on May 30, 2004 9am

Paper doll icon
Cheah Chu Yeow's Gravatar

Hi Chris,

It seems that something was mistyped or mis-copied, because the PHP is being parsed as plain text. If you could show me the template code you have beginning at the referrers part, I would be able to debug it for you :)

PS. I’ve been trying to get you via email but it doesn’t seem to be working.

Posted by: Cheah Chu Yeow on May 30, 2004 2pm

Paper doll icon
Chris's Gravatar

Thank you for you answer, unfortunatelly my spamfilter is not only fighting spammails :-(

Here is my Template code beginning with the referrers part in the individual entry archive template (at the end of the page):

Die letzten 10 Referrer

Note to referrer spammers: The referral links below will have no effect on your Google PageRank. Besides, once you’re in my referral logs, you will be blocked. Save yourself the trouble.

// display the list of referers
echo ‘

Referrers

‘, “\n”;
echo ‘

‘, “\n”;
echo ‘

‘, “\n”;
echo ‘

‘;
?>


Kostenlose Zähler

You can also answer me by e-mail, I will check my spam folders ;-)

Cheers,

Chris

Posted by: Chris on June 7, 2004 1am

Paper doll icon
Mariam's Gravatar

I used this for my article database /articles and I was hoping if you could tell me how perhaps do.

“The [number of articles] have been read a total of [number] times.”

There are so many posts above and are way over my head. I’m sorry if this was asked/answered above.

Posted by: Mariam on June 22, 2004 1pm

Paper doll icon
Chris's Gravatar

Sorry, but I haven’t received an email from you yet. :-(

chris@digitalvoodoo.de

Posted by: Chris on July 6, 2004 5am

Paper doll icon
hello-lovely's Gravatar

More Blogsnobbery
Because I have nothing of importance to post (most of you probably already know that Kerry picked John Edwards as his running-mate), here’s another journey through Blogsnob Land, ended by a page without a blogsnob link! :( + Fembat blogs…

Posted by: hello-lovely on July 6, 2004 11pm

Paper doll icon
Segmentation Fault: Core dumped..;-)'s Gravatar

I am off..
..for a few days, that is. Will be taking some time off from active blogging starting this very moment and will be back in business by 07/20/2004 08/01/2004, if not sooner. Have a few personal, professional and some blog related housekeeping to do. Th…

Posted by: Segmentation Fault: Core dumped..;-) on July 21, 2004 2am

Paper doll icon
Chris's Gravatar

I managed it to get your plug-in working. Now I would like to know how to change the code to display just the last 20 referrers (like on this page), not all.

Further I would like to know how and where to put the code to change the referring link, so that spammers cannot earn pagerank (I am using an outbound.pl cgi script and need to know where to put the ‘http://www.digitalvoodoo.de/cgi-bin/outbound.pl’)

Please answer directly here in your blog as it seems that I cannot receive your e-mails :-(

Kind regards,

Chris

Posted by: Chris on July 25, 2004 8pm

Paper doll icon
Cheah Chu Yeow's Gravatar

Hi Chris,

>> to display just the last 20 referrers

Add the first 2 lines below and the last line at the end of the while-loop:

$displayMax = 20; // max. no. of referrals to display
$displayCounter = 0;
while( $row = mysql_fetch_assoc( $rs ) ) {
$referer = $row[’referer’];
$count = $row[’count’];

// … other stuff

echo “\n”;

if( ++$displayCounter >= $displayMax ) break;
}

>> where to put the code to change the referring link

Instead of:

echo ‘<a href=”‘, $referer, ‘”>’;</a>

Use:

echo ‘<a href=”http://www.digitalvoodoo.de/cgi-bin/outbound.pl?url=’, $referer, ‘”>’;</a>

Customize the URL as per your Perl script.

Posted by: Cheah Chu Yeow on July 25, 2004 10pm

Paper doll icon
irish's Gravatar

I need to know, can this script report a hits?
E.g : when somebody search some keyword in a search engine, and your site with that script is displayed in that current search (but not clicked/visited) . Can it report that ‘thissite.php’ is hit when somebody do a : http://www.google.com/?query=search+free+ebook&display…bla..bla.

If it can do like that .. it will be easy to track what’s best keyword for our site .
thanks.

ps: I also made a tracking referer with a plain text.
check it out at http://newbiewebmaster.blogspot.com

Posted by: irish on August 7, 2004 4am

Paper doll icon
Marina's Gravatar

I wonder if I have a normal blog site structure..I would appreciate your coming to my blog and leaving some “fresh” ideas and proposals concerning what it is better to rebuild or reorganize.
I really need your help …. Thanks.

Posted by: Marina on August 17, 2004 11pm

Paper doll icon
Marina's Gravatar

I wonder if I have a normal blog site structure..I would appreciate your coming to my blog and leaving some “fresh” ideas and proposals concerning what it is better to rebuild or reorganize.
I really need your help …. Thanks.

Posted by: Marina on August 17, 2004 11pm

Paper doll icon
Marina's Gravatar

I wonder if I have a normal blog site structure..I would appreciate your coming to my blog and leaving some “fresh” ideas and proposals concerning what it is better to rebuild or reorganize.
I really need your help …. Thanks.

Posted by: Marina on August 17, 2004 11pm

Paper doll icon
SSP's Gravatar

How long i searched for a Hack like this!
Thank you very much, but i habe a mistake somewhere and my knowledge is to small to find it.

If i add this line:

$rs = mysql_query( ‘SELECT COUNT(*) FROM mt_entryhits WHERE entry_id=< $MTEntryID$>’ );

i get the following error:

Parse error: parse error, unexpected T_STRING in /www/htdocs/denkblog/index.php on line 73

(line 73 is the Line with $rs)

I would be so glad if you could give me a hint.
Thanks!

Posted by: SSP on September 27, 2004 2pm

Paper doll icon
Hongkong's Gravatar

Thank you once more for this great tutorial. It’s workling fine on my weblog, but I have another question:

Is it possible to display a top-10 list of the most read articels on the index site? I think this would be a great gimmick.

Cheers,

Chris

Posted by: Hongkong on November 5, 2004 7am

Paper doll icon
FiReaNG3L's Gravatar

I would be highly interested in a “top 10″ of the most read posts… I sadly use titles AND date (/archives/day/month/title) for my posts, and I can’t figure how to rebuild these links from my MT database (the URL isn’t stored).

Posted by: FiReaNG3L on April 6, 2005 8am

Paper doll icon
FW's Gravatar

Great tutorial, you can see the script in action on my site.

Posted by: FW on March 9, 2006 7am

You can subscribe to the RSS feed for comments on this post.

Sorry, this entry is no longer accepting comments. If you have something you really want to say, you can write me.