Thursday, July 04, 2013
Were you ever wondering if you could have a widget that would let you display the current online visitors on your website? Woohoo.. The gods heard your prayer my friend, those sent me down the earth just for you. "How To Add Online Visitors Counter Widget To Blogger", that's what i'm gonna talk about. Should we cheer for this? :)

Yeah, that seems not too bad if we can have an online visitors counter widget on our blogger blog, isn't? So far the only way that bloggers may know, a way to show the current visitors online, is by using widgets from third parties. That's not what we want, we agree that nobody love third parties in such case, to add some additional codes directly into the template is preferable, or at least we host the code ourselves.

The good news, there is a way to do that, it's using PHP script. However, we all know that blogger doesn't support PHP script, so for this way we need another web hosting to keep the code. There are many free PHP web hostings out there, just google out and you'll see that, or just take a look on my previous post and you'll have some options, here it is: http://j-smith-site.blogspot.com/2013/05/best-free-web-hostings-with-mysql-php.html > Best Free Web Hostings With PHP And MySQL Support

#Code To Show Online Visitors Counter Widget To Blogger

I'm not gonna tell you the detail way to execute the code, imma give you the code just like that with a short instruction, so if you know nothing about PHP script, then take a look on my previous post: http://j-smith-site.blogspot.com/2013/05/create-page-post-views-counter-widget_21.html > Individual Or Single Page Counter / Post Counter Widget For Blogger

Okay, i'm going.

1. Go to the PhpMyAdmin page of your host > Enter to database > Click Sql and insert the following paramater.

CREATE TABLE live_user (session char(100) NOT NULL default '', time int(11) NOT NULL default '0', file varchar(100) NOT NULL default '') TYPE=MyISAM;

2. Copypass the following script and Make it ".php" file.

<?php

session_start();
$session=session_id();
$time=time();
$time_check=$time-300;
$hostname="your_database_host";
$username="your_username";
$password="your_password";
$dbname="your_database_name";
$tblname="live_user";
mysql_connect("$hostname", "$username", "$password") or die("could not connect to the server");
mysql_select_db("$dbname") or die("Could not select Database");
$sql = "SELECT * FROM $tblname WHERE session='$session'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count=="0") {
$sql = "INSERT INTO $tblname(session, time) VALUES('$session', '$time')"; $result = mysql_query($sql);
}
else {
"$sql = UPDATE $tblname SET time='$time' WHERE session='$session'";
$result = mysql_query($sql);
}
$live_data = "SELECT * FROM $tblname";
$live_rows = mysql_query($live_data);
$live_user = mysql_num_rows($live_rows);
echo "document.write($live_user);";
$delete = "DELETE FROM $tblname WHERE time<$time_check";
$do = mysql_query($delete);
mysql_close();
?>


3. Go to file manager and upload the file (.php) to public_html directory.

4. Take the url of the page > Cover it with javascript and put on the website that you want to add the widget, well done!

*This script is working, the one that i published a few times ago is not working.
*To change how long the visitor will be count online since the last click he made in seconds, change the number "300" in the code.

The last thing, if you face any trouble in connection to the widget, you tell me. :)

If you like the above post, you might like these posts too:

http://j-smith-site.blogspot.com/2013/05/create-page-post-views-counter-widget_21.html > Individual Or Single Page Counter / Post Counter Widget For Blogger
http://j-smith-site.blogspot.com/2013/05/page-post-view-counter-hit-stats.html > Daily Page / Post Counter For Blogger
http://j-smith-site.blogspot.com/2013/06/page-counter-post-counter-widget-weekly.html > Weekly Page / Post Counter For Blogger
http://j-smith-site.blogspot.com/2013/06/post-views-widget-based-on-yearly-hits.html > Yearly Page / Post Counter Widget
http://j-smith-site.blogspot.com/2013/05/best-free-web-hostings-with-mysql-php.html > Best Free Web Hostings With PHP And MySQL Support

0 comments:

Post a Comment