Mohon Tunggu ...
Your Ad Here

Monday, December 31, 2007

Tutorial Making Website Counter With File As Database


Begin Of Article

With website counter or in indonesian is called “penghitung jumlah pengunjung” in a website, we can know how often that website was visited by peoples or visitors.


On this chance I will share about how to make a simple and easy website counter. Although we know that very much the free website facilites about it in internet, such as: hitstat.com ( serve more website counter with dinamic and artistic appearance and more kinds who can choosed by his members).


Despite that, has more spread around of websites that serve this facilites, but won’t quite if our website is not completed with website counter made by us.


The website counter that will we do, in this chance is not use Mysql as database, but only use a file as database, it is easy, isn’t it! Ok see this script here..



<?
// Code Of Website Counter
// Open Source For You

// Created by didin noerdin  ahmadi
// at 26 December 2007
// http://pqcms.blogspot.com

$handle =  @fopen("db.txt", "r+"); 

// obtain the files that as a  database
if ($handle) {
if (!feof($handle)) {
$buffer = fgets($handle, 4096);

// obtain the content of the  database file
$data=chop($buffer);  

// save the content into $data variables and clean from space
fseek($handle,0);

// back to first pointer
$data++;

// increase 1 for the content of database file
if (!isset($_COOKIE['guest'])){
setcookie('guest',true,time()+7200);

// give sign for the  last visitor
@fputs($handle,$data);

// write the new of count visitor
}else{
echo "Welcome Guest! Your IP is  ".getenv(REMOTE_ADDR);
}
echo "<br /> You are the visitor  <h2>$data</h2>";

// display the result of visitor count into  web browser
}}

fclose($handle);// close the  access to database file 

?>


 


Wew.. the script code above can you copy and paste directly. But before you do it, you must make a file as a dabatase with name “db.txt” (in that example code).

$handle = @fopen("db.txt", "r+");


the definition of  abbreviation code is open a file as database. And the character @ is use ignore more error if it be happen. To get more further explaining about it (@) you can visit this link at http://pqcms.blogspot.com/2007/11/lahan-dollar-slashmysearch-error-what.html


$buffer = fgets($handle, 4096);

the fgets() function is use to read more datas/ content of “db.txt”. $handle variable that save the result process of accessing database “db.txt” as a database.


$data=chop($buffer); 

variable $data will save the value of $buffer, which $buffer is contain about the content of database “db.txt”, the chop() function is use for leave more space character in all section of words. first character or last character.


fseek($handle,0);

the fseek() function is use for placing the pointer at “db.txt” with the first position.


$data++;

we know that $data is contain with value from $buffer variable, and $buffer is contain about a content from file “db.txt”. as a result $data will save the content from “db.txt” indirectly. Besides the script of ++ after that is use for increase/ add one value at $data variable.


if (!isset($_COOKIE['guest']))

the script code of it is related with cookies, before continue it, I will ask you, do you know about cookies??. Okay I think the our discussion will broad to the cookies. No matter!


Okay to add our knowledge of website programming, I will explain about cookies a little.


The cookies if we may mention it, is the people that discard them time in the parties untul his work is let. That mean who I get from a dictionary, but The definition about cookies is not like that,  but the cookies is a Id card, or the mark can be knowed, and ir usualy use for verification or authentication a login form. I will give you an example, when you have logged in successfullly, in someone your email, it will make yours cookies automatically,  and you will see the greeting from your mail such as “Welcome Roy!, Welcome Hansen!, etc”.

When you logged out successfully,  it will destroy your cookies automatically, and you can’t known again, you will see “Welcome Guest!”.


To more believe you, please open the firefox browser anything version, but I use firefox 2.0.0.6 version. If you still use Internet Explore for surfing or browsing, uhh to slow.. if use it.  The better you use the firefox and you can download here!


Download firegfox

 


Wow..I’, I explain a little about firefox…he.he..he..! Ok the next, please open your firefox >> Tools >> Option >> Privacy >> Show Cookies


what is cookies? apa itu cookies?


Look at that pict, we know that the guest greeting, that is your Id Card/ your cookies. Ok its easy, isn’t it!


Back to the website counter script.

if (!isset($_COOKIE['guest']))

the definiton of script on abouve is to check are the guest cookies  is there? Or not?

{

    setcookie('guest',true,time()+7200); // give sign for the last visitor

    @fputs($handle,$data);// write the new of count visitor

}

then next with the code above, if guest cookies is not found, then this code will make the guest cookies for you. With duration value 2 hours. Yess… like that the means…

setcookie('guest',true,time()+7200);

 the setcookie()  function is use for make a cookies, “guest” cookies is a name of that cookie. Then time()+7200 is the duration of expired that cookies, the time() function is mean now time with milisecond and the 7200 is mean 2 hours , 3600 one hour and like that the next. Then the cookies will destroy if the duration is used up automatically.


fclose($handle);// close the access to database file

the last the fclose() funtion is use for closing the accessing database file “db.txt”


Ok this articles was finished. And I hope you can understand about this articles.

If this code is not good or any problems that you found here, you can download the original script code at here!




DOWNLOAD SAMPLE OF VISITOR COUNTER WEBSITE




End of Article




in download pages, you will found more files to be downloaded, such as: download virus code W.32. Generic, the Simple Content Management System With PQCMS.Ver.0.1, tutorial to design joomla template, tips and tricks to prevent the virus from USB flash disk to computer/ notebook, etc.

The Top Articles here: Tutorials To Making Your blog or Website Famous In the Google Search Engine , tutorials to Making Your blog or Website Famous In the Google Search Engine (Indonesian Version) , Save your computer from Viruses in more flashdisk with your hand alone , Get $25 dollars in one day only register in here it is free , Get Money with register in more sites wow, it is free , tips to download Video From Youtube.com


 


 

No comments: