473,508 Members | 2,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unique Website Counter

155 New Member
I made a website for a group of people and they want a visitor counter on it. I don't like hit counters because if the site is dead everyone will know it. But, it's their website.

I did an Internet search but didn't find exactly what I was looking for. I did find an old tutorial, from which I've pasted the code below.

I need it to be session controlled and I only want it to count unique visitors. I want to use a database to keep track of the number of unique visitors to the website - not a particular page.

I use a functions.php page for my websites that contains the head and foot sections of the website:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $page_title = "Home";
  3. include("functions.php");
  4. do_html_header($page_title);
  5.  
  6. echo "<h1>$page_title</h1>
  7. Home page website stuff
  8. ";
  9. footer();
  10. ?>
  11.  
At the top of my functions.php page I have the code that I mentioned above. This code is suppose to count unique visitors to the website, but it's not working.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. function do_html_header($page_title)
  3. {
  4. global $counter;
  5. include("includes/dbconnect.php");
  6. session_start();
  7. if (!isset($_SESSION[countme])) {
  8. $_SESSION[countme]="set";
  9. $sql="SELECT * FROM $c";
  10. $result = mysql_query($sql);
  11. $row = mysql_fetch_assoc($result);
  12. $count = $row['value'];
  13. //Increment Counter
  14. $count = $count + 1;
  15. //Update Database
  16. $sql="UPDATE $c SET value=".$count."";
  17. $result = mysql_query($sql);
  18. }
  19. echo "
  20. <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>
  21. <html>
  22. <head>
includes/dbconnect.php connects to the database and assigns the database table for the counter to the variable - $c.

The counter table has these: cid, value.

This script may be old and outdated, which may be why it's not working. Anyone see a quick fix to this script or can point me in the direction of a better php, mysql, sessions counter script?

Thanks
DavidPr


** UPDATE **

It may be working after all. I started out with the number 7595 in the "value" column in the database table, now I have 7598. When I first installed the script and went to the website the value number did not increase in the database table. I don't know why there would be a delay in the number increase, but perhaps I jumped the gun on this.

But if anyone can see where this script could be improved I'd like to hear about it. Thanks, and sorry for the confusion.

DavidPr
Jul 10 '09 #1
3 3074
Dormilich
8,658 Recognized Expert Moderator Expert
I'm quite fond of this counter (chcounter)—it has really a lot of features and it could also fit your needs (besides that you don't need to do any programming on it)
Jul 11 '09 #2
DavidPr
155 New Member
Looks interesting, but I can't read German and I didn't see an English translation link.

Thanks
Jul 11 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
there doesn't seem to be an English translation of the web site, though the counter itself has been translated into English…

otherwise I recommend looking for a counter at a script archive, this really saves you lots of trouble.
Jul 12 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
10846
by: Kamil | last post by:
Hello What should I use for better perfomance since unique constraint always use index ? Thanks Kamil
4
10723
by: August1 | last post by:
A handful of articles have been posted requesting information on how to use these functions in addition to the time() function as the seed to generate unique groups (sets) of numbers - each group...
3
1700
by: GM | last post by:
Hello all, i have a question i've beenk thinking for a little bit and cant seem to come up with a solution. What i want to do is add a unique counter to a resultset in query. For example SELECT...
1
1382
by: J.J. Feminella | last post by:
I have an unfinished small class hierarchy that looks something like the code snippet below. The intent is to have a simple company identification system that ensures uniqueness by calling...
3
2842
by: petermichaux | last post by:
Hi, Is there an internally assigned number for each JavaScript object that I can read? If so how would I do that? Thanks, Peter
15
2047
by: A. Farber | last post by:
Hello, I'm programming a web game on OpenBSD, but am also trying to keep in runnable on Linux and Cygwin. I have a list of tables at which a player/kibitzer can sit down or create a new empty...
8
7187
by: Marc | last post by:
Hi all, I have to generate and send to a printer many 6 digit alphanumeric strings. they have to be unique but I cannot check in a database or something like that if it have already been printed....
12
28406
by: badvoc | last post by:
Hi, I have had some good fortune on this site so I am back and I must iterate I am a beginer. I am having some problems getting to grips with the right technique to manage variables and...
3
6399
by: Dev | last post by:
Dear All, i have get combination of four PHP script for count the visitor of website but when i apply all these i have no answer. i am posting the code of all four PHP script below. CODE OF...
0
7227
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7127
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7331
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7391
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7501
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
424
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.