Make Your Own Very Simple Counter Using PHP!

Pages: 1, 2, 3, 4
free web hosting
Free Web Hosting > Computers & Tech > How-To's and Tutorials > Programming > PHP

Make Your Own Very Simple Counter Using PHP!

jcguy
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.

Reply

Darren
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.

Reply

thedevil
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...

Reply

yordan
@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.

Reply

little0run
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?

Reply

Jikson26
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.

Reply

Alexandre Cisneiros
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.

 

 

 


Reply

PureHeart
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

Reply

yordan
@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.

Reply

jipman
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

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

Pages: 1, 2, 3, 4
Recent Queries:-
  1. "php" make a counter - 0.99 hr back. (1)
  2. how to build a basic counter - 3.80 hr back. (1)
  3. how do i put a counter on my page using php - 8.26 hr back. (1)
  4. using counter in php - 8.72 hr back. (1)
  5. how to build a shop counter - 10.36 hr back. (1)
  6. design my own counter php - 12.41 hr back. (1)
  7. own php web counter - 18.03 hr back. (1)
  8. how to make counter on link - 19.73 hr back. (1)
  9. make a unique counter using php - 22.40 hr back. (1)
  10. how to write your own statistics counter in php - 23.73 hr back. (1)
  11. how to make own people counter - 25.70 hr back. (2)
  12. simple counter php - 20.79 hr back. (2)
  13. php tellen count page loads - 27.93 hr back. (1)
  14. create a counter in php - 29.57 hr back. (1)
Similar Topics

Keywords : make, simple, counter, php

  1. Php Counter
    (4)
  2. How To Create A PHP Based Hit Counter
    With MySQL (2)
    websaint recently posted a PHP hit counter using a flat-file to store information. This is a guide
    a wrote a little while ago - it was for another web site, but I'll post it here as well.
    ----------------------------------------------------------------------------------- First and
    foremost, you need to create a new table. You can use a whole new database if you want (and assuming
    you have one free), but it's a bit of a waste. For this guide, our table will be called
    'hits', and will contain two fields - 'unique' and 'total'. The first ....

    1. Looking for make, simple, counter, php






*SIMILAR VIDEOS*
Searching Video's for make, simple, counter, php
advertisement




Make Your Own Very Simple Counter Using PHP!