Jump to content



Welcome to AstaHost - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!

Toggle shoutbox Shoutbox Open the Shoutbox in a popup

@  yordan : (19 June 2013 - 02:28 PM) Long Life To Asta New Era
@  agyat : (19 June 2013 - 01:58 PM) New Era Start At Asta Or Asta Start In New Era. :unsure:
@  yordan : (16 June 2013 - 05:41 PM) You're Welcome, Agyat!
@  agyat : (16 June 2013 - 07:38 AM) Thanks Yordan...
@  velma : (16 June 2013 - 12:06 AM) I Have Asked Opa To Check For A Backup.. He'll Let Me Know Soon :)
@  velma : (16 June 2013 - 12:05 AM) T_T It Seems That Someone Has Deleted That Topic Since I Found The Url Of The Topic But It Gives Me An Error
@  yordan : (15 June 2013 - 10:31 PM) @velma : It's A Tuto On How To Create A Login Program.
@  yordan : (15 June 2013 - 10:31 PM) Happy Birthday To Youuuuuu Agyat!
@  yordan : (15 June 2013 - 10:31 PM) Ba$
@  agyat : (15 June 2013 - 04:41 PM) :(
@  agyat : (15 June 2013 - 04:41 PM) Where The Hall I Were? 15Th Is Almost At End And No-One Wished Me "happy Birthday"!!!
@  velma : (14 June 2013 - 10:39 AM) Which Tutorial Is He Searching For?
@  velma : (14 June 2013 - 10:38 AM) Which Tutorial Is He Searching For?
@  yordan : (14 June 2013 - 07:47 AM) Ok, Have A Look Tomorrow.
@  yordan : (13 June 2013 - 03:19 PM) @velma, Can You Have A Look At Feelay's Problem? Seems That His Tutorial Is Not Searchable Today.
@  Feelay : (13 June 2013 - 08:11 AM) Oh, Haha
@  velma : (12 June 2013 - 05:39 PM) T_T Lately My Levels Of Procrastination..... **sigh**
@  velma : (12 June 2013 - 05:38 PM) I'll Do It Later
@  velma : (12 June 2013 - 05:38 PM) Procrastinators.. People Who Keep Saying "i'll Do This In A Bit"
@  Feelay : (12 June 2013 - 02:05 PM) Deal Punishments To What?

Replying to Make Your Own Very Simple Counter Using PHP!


Post Options

    • Can't make it out? Click here to generate a new image

  or Cancel


Topic Summary

yordan

Posted 14 June 2012 - 07:56 PM

is this for online counting? for example: "Now 3 online visitors". Or for general counting?

If you read the example you will notice that it adds +1 to the counter each time somebody enters there.
So, if you put it somewhere on your main page, it will tell you how many people read this page.
If you clear the content of the file each morning, at the end of the day it will tell you how many people today. If you don't clear "alle.txt" it will tell you the total number since creation of the file.

Posted 14 June 2012 - 06:21 PM

is this for online counting? for example: "Now 3 online visitors". Or for general counting?



Hi!! I'm going to show you how to make your own counter useing php!! :) It's really easy and you woun't have to keep seaching the net for free and bannerless counters.
So here comes the script:

<?php

//Simple class for counting visits
//Written by WebSaint

class Teller {
   function count() {
   $countfile = file("alle.txt");
   $count = $countfile[0];
   $count= $count + 1;
   $fp = fopen("alle.txt","w");
   $fw = fwrite($fp,$count);
   fclose($fp);
   echo $count;
   }
}

$obj =& new Teller;
$obj->count();

?>
Then add this to display the number of visitors:

<p>Number of guests visiting my site: <? include('alle.txt'); ?>.</p>

That's it. I hope you'll find the script useful! :)


Posted 29 April 2010 - 01:58 AM

Does the code hate me or is it wrong?Make Your Own Very Simple Counter Using PHP!

I've integrated my code and it counts double, it started like such: 11 and then when I refresh it adds another 11 so, it goes by 22 and then 33. Really bad :(


rockarolla

Posted 17 February 2008 - 05:00 PM

file based counter may jam - sometimes it wont be able to overwirte the data - when many visitors navigate to your web.

The other problem is if you ain't got permissions to open a file on your server...hence host dependent.

comkidwizzer3

Posted 16 February 2008 - 02:37 AM

Good... but you might find others steal your counter if they find it...
they will link to your counter script, and store their page cound on your server.

its always good to add some kind of proetection againsed this. a good, but not perfect way is to make sure the referer comes from your own site, and nobody elses.



you misunder stand my meaning.......

i mean someone could replace

<p>Number of guests visiting my site: <? include('alle.txt'); ?>.</p>

the include file with a coomplete URL to anouther server. and replace "alle.txt" with a different filename.


A solution to your problem just encode your webpage.

optiplex

Posted 04 May 2007 - 09:38 PM

verry good & no mysql !

livingston

Posted 21 March 2007 - 07:27 PM

wow a great simple and effective counter.

warallthetm

Posted 09 July 2006 - 05:33 PM

Dose this script count page loads or unique ips? I have been searching fo a php script that count's unique visitors and not just page loads. Is there a way to mod this?

XIII

Posted 09 April 2006 - 12:16 AM

This will not insert any data into the database, it will always say 0 Hits

WOW, i found a solution:

$conn = mysql_connect("localhost","db_username","db_password") or die('MySQL said:  ' . mysql_error());
$db = mysql_select_db("db_name");
$sql = mysql_query("SELECT * FROM counter") or die('MySQL said:  ' . mysql_error());
while($visits = mysql_fetch_array($sql))
{
$visits = $visits['visits'];
$visits_new = $visits + 1;
}

$query = "UPDATE counter SET visits = '$visits_new'";
mysql_query($query, $conn) or die(mysql_error());

echo "$visits_new Visits";


i removed TABLE from:
$query = "UPDATE TABLE counter SET visits = '$visits_new'";
and don't forget to set the visits value in the database to zero or any number you want, just don't leave it as default.

XIII

Posted 08 April 2006 - 03:24 PM

Try modifying that line to:

$query = 'UPDATE TABLE counter SET visits = "$visits_new" ';

Try this and let me know if it still produces the same error.


Now i got the same error, really so strange case to me :lol:

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'TABLE counter SET visits = "$visits_new"' at line 1


Review the complete topic (launches new window)