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

@  agyat : (23 May 2013 - 01:23 AM) Wow! Mr. Sb Back Home.
@  OpaQue : (23 May 2013 - 12:44 AM) Ting
@  OpaQue : (24 April 2013 - 02:44 PM) I guess, Time to run Mycent script.
@  OpaQue : (24 April 2013 - 02:43 PM) wow.. not much spam. except habatt posting lot of links.. :P
@  yordan : (23 April 2013 - 01:04 PM) You're welcome, agyat. Nice to have been helpful. Second lesson: try full words, "you" instead of "EW".
@  agyat : (23 April 2013 - 05:03 AM) @YORDAN: tHANK EW FOR YOUR FIRST LESSON.   :D
@  yordan : (22 April 2013 - 09:43 PM) @agyat : "why don't you help me", or "please help me", or "please teach us"
@  yordan : (22 April 2013 - 09:42 PM) welcome back, velma
@  velma : (22 April 2013 - 07:51 AM) **yawns** Good to be back, wonder what is going on here :)
@  agyat : (22 April 2013 - 03:50 AM) Oh! so, why don't help me learn english..
@  yordan : (21 April 2013 - 08:38 PM) The goal mentioned by shiu : "learning english, learning computer"
@  agyat : (21 April 2013 - 06:31 PM) WHAT GOAL?
@  yordan : (20 April 2013 - 10:39 AM) yes, that's our goal. simultaneouly learning English and teaching/learning computer using.
@  shiyu : (20 April 2013 - 07:30 AM) learning english,learning computer
@  yordan : (19 April 2013 - 01:11 PM) Oh, I see, it's just a trick in order to force people looking at your texte. Somehow smart, maybe.
@  agyat : (19 April 2013 - 02:54 AM) And of course I know it is not SEO friendly.
@  agyat : (19 April 2013 - 02:52 AM) There may be two possible answers for that ....


1) Shout was posted using mobile keypad.

2) To force people read content carefully and/or with more concentration.
@  agyat : (19 April 2013 - 02:49 AM) There may be two possible answers for that ....
@  yordan : (18 April 2013 - 09:35 PM) however, why this mixing of capital letters in the middle of your text?
@  agyat : (18 April 2013 - 11:10 AM) false feelings.

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)