Sunday, June 02, 2013
Finally, we got on weekly views now, and this means that we're almost done with Page Views Counter or Post View Counter Widget. Make sure you have also read my previous posts if you don't know or if you want to have some other page counter widgets, i have published many, Online Users Counter, Individual Post Views Counter, Daily Post Views Counter, and Total & Unique Views Counter Widget. For online users counter, i am sure will soon publish another one to kill the widget since it doesn't work exactly i'm expecting, and you are expecting what i am.

Additionally, take a look also on the following post to know how to unite the counter widgets i have published, and those that i'm going to publish, into one place: Create table form for custom page counter widget. You better put the widgets all at once, in a single holder, if those are many or least some, it's suposed to make your widgets look better, to make the widgets a widget, a perfect widget of custom page counter.

How To Create Page Counter Widget Based On Weekly Views

It's easy, realy easy. You only have to copypass the code i'm going to give here and upload or publish it on your own page. However, you can't just publish it on any page, it requires you to publish on a page with PHP and MySQL support. Take a look on the following article if you know nothing, have no and want to have a webpage, web hosting, that supports PHP and MySQL language, Best Free Web Hosting With PHP and MySQL Support.

Or if you'd like to know how way exactly to implement page counter widget on your website, since some of those require you to create a table and database for keeping data (But weekly page views counter does not need those), not just about publishing a new webpage like you'd do on a normal web hosting, like blogger for example, you can read my first post about page counter widget, you go here: Individual Page View Counter.

Well, i'm going. :)

1. Create two new text files (.txt) and simply fill those with a single number 0 respectively.
2. Upload the text file to your root directory, it's where your folder public_html located.
3. After you're done with your upload, Chmod the files to 777.
4. Copypass the following script and make a .php file.

<?php
$fs = "weekly_stats.txt";
$fs2 = "weekly_stats_2.txt";
$fp = fopen($fs, "a+");
$fp2 = fopen($fs2, "a+");
$file = filesize($fs);
$file2 = filesize($fs2);
$date = date("w/n/y");
if(strpos($date, "0") == 0) {
if($file != 0) {
ftruncate($fp, 0);
}
if($file2==0) {
$result = 1;
fwrite($fp2, $date."-".$result);
}
else {
$fr = fread($fp2, $file2);
$data = explode("-", $fr);
ftruncate($fp2, 0);
$result = $data[1]+1;
fwrite($fp2, $date."-".$result);
}
}
elseif(strpos($date, "0") != 0) {
$fr = fread($fp2, $file2);
$data = explode("-", $fr);
if($file2 !=0) {
ftruncate($fp2, 0);
}
if($file==0) {
$result = $data[1]+1;
fwrite($fp, $date."-".$result);
}
else {
$fr = fread($fp, $file);
$data = explode("-", $fr);
ftruncate($fp, 0);
$result = $data[1]+1;
fwrite($fp, $date."-".$result);
}
}
fclose($fp2);
fclose($fp);
echo "document.write($result);";
?>

Here to copy


5. Now upload the file (.php) to your folder public_html and that's it, well done! Your weekly page counter is ready to run.

The only thing that you have to note about the code is that you need to replace the lines in red with your own text files' names, two text files that you uploaded to your root directory. If you named those weekly_counter.txt and weekly_counter_2.txt, for example, then replace those with that names.

I use the above code exactly like that, and it's working. And surprisingly, i created it myself, but definitely i have learned many of such a code before i made up. I wanted to put the data in a single text file but i couldn't, i had no idea how to do that, hope sometime i find out how. :)

Speak english. The code is created for public, no ads, no links back, and no charge, just free. If you'd like to edit the code, then go ahead, i don't think like i own the code.

0 comments:

Post a Comment