Tuesday, May 21, 2013
A little differs from the two posts before: Page Views Widget that lets you know total views or hits of your website, and Post Views Widget that lets you show total views or hits of every single pages on your website. Now i will show you How Can You Create An Online Visitor Counter widget. This widget will let you show to your visitors how many readers are being online or accessing your website, additionally you will even be able to show how many readers are being online on the current page.

I guess it's difinitely the right time for you to say goodbye to the third party, if any, that currently you use to show page hits and online visitors on your website, there is no reason anymore to use it. I have given you a total page hits counter, single post views counter, unique visitors counter, and now finally i'm going to give you an online visitors counter widget. Yeah, i haven't found yet a page views counter to show your monthly visitors, or weekly and daily visitors, but i guess those are quite enough to replace your third party, are not those?

About daily visitors counter, by the way, i have a counter widget that will let you show that, just, it's not in plain text, it's using image. I will likely give it to you, but the matter for you is that you can't put the widget together with the other ones that i have already given to you. You can put it together with the other ones, of course you can, that's not realy exactly the matter i'm talking about, the matter is how those will look like if you join all together.

However i haven't realy learnt the code yet, i will take a look once again to make sure that i realy don't understand it, to make sure that i can't do anything with the code, to make sure that i can't turn it to show the number of page views as plain text. We'll see that..

How To Create An Online Visitors Counter Widget For Blogger

It's easy, like previously you created your post views counter, to create Online Visitors Counter you only need to create a new table and publish one php script, for the database you can use the existing one.

Please read here if you are not familiar or you don't know how to create a new database to store your data: How To Create Page View Counter Widget?. There you can read the complete tutorial about creating counter widget.

Steps To Create Online Visitors Counter Widget

1. Go to control panel > MySql > PhpMyAdmin > SQL > Copypass the below command into the text box

CREATE TABLE `onlineuser` (
`timestamp` int(15) NOT NULL default '0',
`ip` varchar(40) NOT NULL default '',
`file` varchar(100) NOT NULL default '',
PRIMARY KEY (`timestamp`),
KEY `ip` (`ip`),
KEY `file` (`file`)

Needless to fill the two columns, table and rows, as i said on my first tutorial. Right away click SQL after you get into PhpMyAdmin, paste the above command, and it will create a table named onlineuser.

2. Go to control panel > File manager > Upload the following php script


$host = 'localhost';
$username = 'a6559_stat';
$password = '2345';
$db_name = 'a6559_stat';
$timeoutseconds = 240; --> How long the user will be kept by your database in seconds
@mysql_select_db($db_name) or die("Unable to select database");

mysql_query("insert into onlineuser values('$timestamp','$REMOTE_ADDR','$PHP_SELF')") or die("<b>MySQL Error:</b> ".mysql_error());

mysql_query("delete from onlineuser where timestamp<$timeout") or die("<b>MySQL Error:</b> ".mysql_error());
$result = mysql_query("select distinct ip from onlineuser") or die("<b>MySQL Error:</b> ".mysql_error());
$user = mysql_num_rows($result);
$resulta = mysql_query("select distinct ip from onlineuser where file='$PHP_SELF'") or die("<b>MySQL Error:</b> ".mysql_error());
$usera = mysql_num_rows($resulta); mysql_close();

if ($user==1) { echo "document.write($user);"; }
else { echo "document.write($user);"; }

if ($usera==1) { echo "document.write($user);"; }
else { echo "document.write($user);"; }

Here to copy


*Replace all lines in red using your parameter
*The following are lines that call the functions

if ($user==1) { --> Total Online
echo "document.write($user);";
else {
echo "document.write($user);";

if ($usera==1) { --> On Current Page
echo "document.write($user);";
else {
echo "document.write($user);";

3. Last step, finally copy the url of your page, and use it to call the script from your website

Well done! Now you have your own online visitors counter widget for your blogger blog. Wait for some more widgets, at least i have a daily page views counter.


Post a Comment