So far blogger has not yet added any counter widget officially, don't know why, but i'm sure it's not because blogger can't create the widget. It must be easy, like a piece of cake for blogger to create the widget, even there is a popular post widget that's been already existing for years. How the popular post widget determines which posts are most popular if it doesn't read from page views, what do you say about it my friend? No way it goes by search through google, you bet..
But, hey.. You calm down, the pain is no more right? Here i'm going to tell you how can you create your own custom page views. Wipe out your tears friend, i can't see that.. :)
How To Create Page Views Widget For Blogger
It's not too easy to create a custom post views widget for blogger, yet it's not too hard maybe. There are some steps that you have to do, those like creating mysql database, table, publish a php page, and somekind. For those, you need to sign up for a new hosting that support mysql and php language, if you don't have it yet.There are many such hosting that you can find, just search through google, or may be better if you ask your friends. But wherever you sign up to, i suggest you not to sign up to 000website.com, the code will not work if you call it from your website. I guess it's because the pages given by 000webhost.com are not an empty page, those contain some contents already by default, like one that you can find is page counter.
I myself host my script on idhostinger.com. It's free for good, you'll have 2GB space, 100GB bandwitch, and 2 mysql database, i can't remember all services that the hosting offers, so take a look if you'd like. But, as any other free service, it's regularly dropping the service. What the terms for that? :)
Steps To Create Post Views Widget For Blogger
Let's get down to the bussiness, i assume you already have a hosting with mysql and php support here, so if you have not yet, go get it. Cause every terms i'm going to say here, terms that you may not be familiar with, are terms that you can find only on control panel of php hosting. Control panel itself, or cpanel, you call it dashboard on blogger..1. Go to control panel on your hosting
2. Click Mysql database
3. Create a new database
There are about three points here, name for database, username, and password. I suppose you fill those with:
database name: stat
database username: stat
database password: 234
Your database name will be like this: a265663_stat
4. Go back to control panel, and click Mysql database again
5. Now you'll find the database that you have just created, right beside the database you'll see PhpMyAdmin, click it
Might you'll be asked for a password here, i assume you know how to find or create the password, i forgot how i created mine. Try to insert 234, if it doesn't verify, go back to control panel and click PhpMyAdmin
6. Now you have gotten into the PhpMyAdmin right? There must be available two columns for creating table, column for table and rows. Say you fill in counter for the table and 3 for rows here. Now click go, or create, or whatever to execute it
7. You'll be taken to a page where you can see things that will likely get you sick, don't even try to understand anything. Just pay attention on the top, left, or maybe right side, find SQL link and click it, insert the following into the text box given:
CREATE TABLE `Mysql Database`.`Table Name` (
`SN` BIGINT NOT NULL AUTO_INCREMENT , `name` VARCHAR( 1000 ) NOT NULL , `hit` BIGINT NOT NULL DEFAULT '1', PRIMARY KEY ( `SN` )
) ENGINE = MYISAM
Note: Replace lines in red using your own mysql database and table name
8. Now go to control panel and click File manager to upload a php script, i'm about to give you that script
There could be three file manager (first try file manager number 3), your mission here is to find and upload a file to a directory called public_html. So first find which one betwen the three file manager will give you access and let you upload file to the directory. When you find the directory, public_html, click it, there might be some files inside, delete all of those and upload your file, exactly upload the following script:
<?php
Header("content-type: application/x-javascript");
$url = getenv("HTTP_REFERER");
$url = str_replace ("http://",'',$url);
$url = str_replace ("www.",'',$url);
if ($url != "")
{
$username = "Put your database username here"; $password = "Put your database password here"; $database = "Put your database name here";
$table = "Put your table name here";
$link = mysql_connect('localhost', $username, $password);
if (!$link)
{ die('Could not connect: ' . mysql_error()); }
$db_selected = mysql_select_db($database, $link); if (!$db_selected) { die ('Could not select database : ' . mysql_error()); }
$query = "Select hit from $table where name = '$url'";
$result = mysql_query($query);
if (!$result) { die('Invalid query: ' . mysql_error()); }
if (mysql_affected_rows()==0)
{
$query = "Insert into counter (name) values ('$url')"; $result = mysql_query($query); echo "document.write('1');";
if (!$result)
{ die('Invalid query: ' . mysql_error()); }
}
else
{ $hitcount = mysql_result($result, 0); $hitcount++; echo "document.write('$hitcount');"; $query = "Update counter set hit = $hitcount where name = '$url'"; $result = mysql_query($query);
if (!$result)
{ die('Invalid query: ' . mysql_error()); }
}
}
?>
Here to copy
Instructions
*Copypass the code, name it as you want, but make the extension .php
*Replace lines in red using yours
*For 'localhost', it is server where your hosting keeps its mysql database. If there is no notice or warn that tell you that the database is kept somewhere else, you don't have to do anything with it, however if you get a notice from your hosting - Like, our mysql database is hosted somewhere else - then replace that localhost using the address where your hosting keeps its dabase. You can also check it from mysql database tab, Control Panel > Mysql Database
9. Last step, copy the url of the page where you published the script - You uploaded a file, it means you published one new page - and use it to call the script from your website, so your website loads a number anytime it makes a load. Below is how you can call the script:
<script src="http://Your-url.com/counter.php" type="text/javascript"></script>
That's it, you are done. Now you have a page views widget, your own page views widget on your blogger blog. My congratulations for that, what a happy day you have..
If you want a stats counter that will let you show total views of your blogger blog, you wait for me, i give you that. :)
0 comments:
Post a Comment