Ubuntu / Linux news and application reviews.

Some time ago, we published a way to have individual post views displayed in each of your Blogger post. The problem is: there is no hosting plan to handle all the post views for all Web Upd8 readers which have installed this Blogger hack, so the only way around this would be for you to install the script on your own server / web host.

I know of two PHP scripts which can do this, so I will handle each one in this post. Read on!


A. The original individual post views hit counter using an image.


1. Download PNG Counter from HERE.

2. After downloading, extract the archive and open: config.inc.php with a text editor such as Notepad or Gedit (in Linux) and modify this:
$CFG['db']       = false; 

from false to true.

Then modify what's in the double quotes ("") for these fields:
$CFG['dbhost']   = "10.10.10.10:3306";
$CFG['dbuser']   = "username";
$CFG['dbpasswd'] = "password";
$CFG['dbname']   = "database";

with the appropriate values for your hosting. Also, make sure you create a database in your control panel provided by your hosting service.

Also, at the bottom of the file, you'll have:

$CFG['pages'] = array(
'demo'
);

Remove the 'demo' from this array (including the single quotes).

After modifying all this, save the file.

3. Upload all the files to your server.

4. Use the same instructions for inserting the code to your Blogger blog as described HERE but make sure to replace the www.mortgagemeter.net part with the one to your domain / hosting.

You can choose from lots of different images. Just type in http://YOUR_HOST.com/demo.php (presuming you uploaded the counter files directly into your hosting root folder) and see examples of different types of images you can use in your blog posts.

Here is a demo with different digits for the counter, but your uploaded script will have a lot more different digits.

That's it.



B. Using the post views text counter created by Anuj (Open-Source script)


Thanks to Anuj, it's Blogger post views text counter for individual Blogger posts is available to everyone. He had the same issue with the server so you must also install it to your own server. Here's how:

1. Download the script from HERE.

2. Go to your hosting control panel and create a new database, let's call it 'bloggercounter'. Then, go to your PHPMYADMIN page (look for a link in your hosting control panel), select your 'bloggercounter' database in the left, click on the SQL tab and paste this:

CREATE TABLE `bloggercounter`.`counter` (

`SN` BIGINT NOT NULL AUTO_INCREMENT ,

`name` VARCHAR( 1000 ) NOT NULL ,

`hit` BIGINT NOT NULL DEFAULT '1',

PRIMARY KEY ( `SN` )

) ENGINE = MYISAM

(paste it exactly as it appears above, don't change anything), and select Go:




3. Open the counter.php file you extracted from the archive downloaded at step 1, with a text editor, and edit these lines:
$username = "YOUR-USERNAME"; // Enter Your Username and Password Here
$password = 'YOUR-PASSWORD'; // Enter Your Username and Password Here
$database = 'YOUR-COUNTER-DATABASE';  //Enter Your Database Name Here
$table = "YOUR-COUNTER-TABLE"; //Enter Your Counter Table Name Here

The fields have comments so you should know what to enter there. Just make sure that for the database you enter: bloggercounter (like we set the database in step 2) and for the table, enter counter (also like we set it up on step 2).

4. Optional: you can restricts the script so only your blog will be able to use the counter, so that it doesn't destroy your bandwidth quota and don't get huge mysql usage. To do this on top of the counter.php file you have this:
<?php

Exactly under it, paste the following code:
$ip = $_SERVER['REMOTE_ADDR'];
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);

if (strpos($hostname, 'allowd.example.com') === false || $ip !== '192.168.0.1') {
die('Access denied');

Replace allowd.example.com with your blog address and optionally, also enter the ip. This will only allow the script to run for your blog.

5. Upload the script to your server, and insert the following code in your Blogger template (exactly where you want the post views counter to show up):

<script src="http://YOUR_ADDRESS/counter.php" type="text/javascript"></script>

Replacing YOUR_ADDRESS with the address where you uploaded the counter.php file. For more info, visit Anuj's blog.