28, May 2012

A simple counter in PhP - webmaster forum

 
Webdigity webmaster forums
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: A simple counter in PhP
« previous next »
Pages: [1] Print
Instabuck - The easy way to sell digital products online

Author Topic: A simple counter in PhP  (Read 1894 times)
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« on: Aug 26, 2005, 02:09:04 pm »

Here is the code for a very simple counter that you can add to your site :

Code:
<?php
if(file_exists("hits.txt"))
{
    
$hits file_get_contents("hits.txt");
}else{
    
$hits=0;
}
$hits++;

$ha fopen("hits.txt""w");
fwrite($ha$hits);
fclose($ha);
?>

You can add it to the .php page that you want to count, plus you can add this code if you want it to be visible :

Code:
<?php
echo $hits." visitors";
?>

« Last Edit: Aug 30, 2005, 02:36:13 pm by Nikolas »

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Novice Spammer
***
Posts: 100
103 credits
Members referred : 0



« Reply #1 on: Sep 01, 2005, 08:37:57 pm »

I actually prefer the hitcounters that use a database. I feel you can do much more with a database and text files. Its almost a bias. But its good code though for someone who doesnt have a database to work with.
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #2 on: Sep 02, 2005, 10:49:22 am »

The best is having a log analyzer, but all these funzy stuff are not usefull for small sites. I mean you don't need a sofisticated statistics program when you have 30 visits per day...

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Credit Thief
.com pimp
*****
Posts: 1118
0 credits
Members referred : 0



« Reply #3 on: Sep 05, 2005, 07:10:28 am »

Interesting, I'm going to try it out. Perfect for me.

Novice Spammer
***
Posts: 100
103 credits
Members referred : 0



« Reply #4 on: Sep 08, 2005, 06:32:10 am »

Yea I guess you are right, small sites dont need an advanced stats tracker.
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=2
Tags : php databases Bookmark this thread : Digg Del.icio.us Dzone more....

Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: A simple counter in PhP
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 28, 2012, 08:07:41 am





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!






Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2012 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.