XIII 0 Report post Posted April 9, 2006 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. Share this post Link to post Share on other sites
warallthetm 0 Report post Posted July 9, 2006 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? Share this post Link to post Share on other sites
delivi 0 Report post Posted March 21, 2007 wow a great simple and effective counter. Share this post Link to post Share on other sites
optiplex1405241546 0 Report post Posted May 4, 2007 verry good & no mysql ! Share this post Link to post Share on other sites
comkidwizzer3 0 Report post Posted February 16, 2008 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. Share this post Link to post Share on other sites
rockarolla 0 Report post Posted February 17, 2008 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. Share this post Link to post Share on other sites
iGuest 3 Report post Posted April 29, 2010 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 Share this post Link to post Share on other sites
iGuest 3 Report post Posted June 14, 2012 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 WebSaintclass 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! Share this post Link to post Share on other sites
yordan 10 Report post Posted June 14, 2012 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. Share this post Link to post Share on other sites