Welcome Guest ( Log In | Register )



4 Pages V  < 1 2 3 4 >  
Reply to this topicStart new topic
> Make Your Own Very Simple Counter Using PHP!
jcguy
post Oct 8 2004, 03:51 PM
Post #11


Premium Member
Group Icon

Group: Members
Posts: 382
Joined: 5-September 04
Member No.: 255



I personally use and would highly recommend Statcounter, a free counter tracking service. It's so much more powerful than other free counters with its advanced visitor reporting and more.
Go to the top of the page
 
+Quote Post
Darren
post Oct 13 2004, 05:57 AM
Post #12


Premium Member
Group Icon

Group: Members
Posts: 205
Joined: 8-September 04
From: Vic, Australia
Member No.: 394



As I said in the other Forum I have also used statcounter and suggest you at least try it. It is ad free and u have the option to make it invisible or give it a range of colours. You can also with the one acount use it for multiple sitesand pages.
Go to the top of the page
 
+Quote Post
thedevil
post Nov 18 2004, 04:52 AM
Post #13


Member - Active Contributor
Group Icon

Group: Members
Posts: 82
Joined: 17-November 04
Member No.: 1,392



ok I use the Mysql database to store the counter results. coz i have a database maintained already for the site...
the code is simple just fetch the row with the counter...
and use echo display on the page...
why bother about the security... The data base is secured...
Go to the top of the page
 
+Quote Post
yordan
post Sep 7 2005, 08:49 AM
Post #14


Way Out Of Control - You need a life :)
Group Icon

Group: [MODERATOR]
Posts: 2,191
Joined: 16-August 05
Member No.: 7,896
myCENTs:34.68



@Darren : seems to be interesting from what you say. I will give statcounter a try, and will compare to astahost's one. The one from astahost is also really impressive, I like it. Besides that I forgot my statcounter's password, and I am still waiting for the mail with it.
Yordan

OK, Darren, your are right, statcounter is really great. Their counters are not so nice as astahost ones, and the menus to step inside are not really easy to understand, and I experienced several disconnections in the middle of the process of creationg your counter. But if you want something really simple, without any ads, it's a simple line to be included inside your html source. And it works anywhere, including on your own PC for testing purposes, which is not the case for the astahost counter.
So, if you want something easy to implement, very nice, with a comfortable menu-diriven settings, use astahost's cpanel one. If you want something simple, which works on any site including your PC, use statcounter.
Go to the top of the page
 
+Quote Post
little0run
post Sep 7 2005, 09:19 PM
Post #15


Advanced Member
Group Icon

Group: Members
Posts: 114
Joined: 22-May 05
Member No.: 5,329



Not too bad, it's a pretty simple counter, but it get's the job done.
I've been trying to figure out this one though, how do we make a download counter, that one is a bit harder isn't it? I suppose we'd make a page that would open the file's URL in a redirect, but also add to the counter and direct them to that instead of the counter?
Go to the top of the page
 
+Quote Post
Jikson26
post Nov 15 2005, 06:25 AM
Post #16


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 2
Joined: 17-September 05
Member No.: 8,511



I like your script, it is clean and simple. It's a great use for light purposes. I use this to improve my website.

Although I like to use more heavy stats that give you greater detail in visitors.
Go to the top of the page
 
+Quote Post
Alexandre Cisnei...
post Jan 26 2006, 10:58 PM
Post #17


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 24
Joined: 22-January 06
Member No.: 10,833



If you want one more secure counter, use MySQL Database!
You just have to:
CODE
CREATE TABLE website_counter
(visits int(10))

And put this code in the top of each page that you want to be counted:

CODE
$conn = mysql_connect("YOUR HOST","YOUR USER","YOUR PASSWORD") or die('MySQL said:  ' . mysql_error());
$db = mysql_select_db($db);
$sql = mysql_query("SELECT * FROM website_counter") or die('MySQL said:  ' . mysql_error());

while($visits = mysql_fetch_array($sql))
{
$visits = $dados["visits"];
$visits_new = $visits + 1;
}


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


And where you want to show the number os visits:
CODE
echo ("Visits: $visits_new");


OBS.: I didn't test it. If you got any errors, post here.
Go to the top of the page
 
+Quote Post
PureHeart
post Jan 27 2006, 07:05 AM
Post #18


Premium Member
Group Icon

Group: Members
Posts: 209
Joined: 7-October 05
From: Đà Nẵng City - Việt Nam
Member No.: 8,966



Hmm, I think the counter (at the beginning of this thread) can't be deloyed on busy site. Because if many pages read and write that file at once, there can be a error when accessing alle.txt
Go to the top of the page
 
+Quote Post
yordan
post Jan 27 2006, 02:00 PM
Post #19


Way Out Of Control - You need a life :)
Group Icon

Group: [MODERATOR]
Posts: 2,191
Joined: 16-August 05
Member No.: 7,896
myCENTs:34.68



@Alexandre : your program has a great advantage, you are independent from any provider, so you can use it on a server other than astahost, or even on a server on a private network.
QUOTE
OBS.: I didn't test it.

yes, it has to be tested first. For instance, I am curious to see where $dados is defined.
Go to the top of the page
 
+Quote Post
jipman
post Jan 27 2006, 07:14 PM
Post #20


Pretty please?
Group Icon

Group: Members
Posts: 733
Joined: 28-November 04
From: Holland
Member No.: 1,552



For a simple php counter there's no need to use databases, flatfiles will do fine, the example by websaint is suffice as long as

CODE

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


Is stored on the server and is not changeable or dependable on userinput.

Anyway, I was thinking that using an OOP approach here might be an overkill. What if you take the following PHP file

vc.php
CODE

<?php

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


Basically you know that whenever vc.php is called there is a new page visit so which means that you need the variable $count back.

So all you need to do now in your other php files is to have them include("vc.php") in the code.

eg

index.php
CODE

<?php
echo("hi");
include("vc.php");
?>


This would be failsafe for any crosssitescripting attempts since there's no userinput expected. Also, even if the name of vc.php is known so people can call it directly, it doesn't matter since they could only +1 to your counter, which is also possible if they reload your page 20+ times. Also, people still need to know the name of the counter script, which is quite difficult to guess if they don't see it stated somewhere.

Alternatively, you could also add an ip banning system to this script to check if a user has accessed this site before. Which is not really necessary if you want to know how much your page has been loaded.

About the busy website thing, it'd take quite a lot of requests per second to be faster than the opening and writing of one byte in a single file for it to have a deadlock. Also, If one has a busy site that can accomplish such thing, it'd be wiser to use a database approach since you can generate more statistics than just the amount of page visits (which is only interesting with a lot of visitors).

Ps. Anything flash is bad tongue.gif
Go to the top of the page
 
+Quote Post

4 Pages V  < 1 2 3 4 >
Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics


 



- Lo-Fi Version Time is now: 22nd November 2008 - 09:52 PM