473,756 Members | 6,852 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 3096
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
10873
by: Kamil | last post by:
Hello What should I use for better perfomance since unique constraint always use index ? Thanks Kamil
4
10761
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 consisting of 6 numbers - with a total of 50 groups of numbers. A well-known girl that some publishing companies use to provide introductory level textbooks to various Junior Colleges in the U.S., not surprisngly, asks for this same exact...
3
1719
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 ColumnA, ColumnB, ColumnC, ColumnD FROM AnyCombinationOfJoinsOrTables WHERE SomeConditionIsTrue w The query above will produce a resultest of 4 columns.
1
1394
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 IsUnique() and allows for variations between different types of ID. (This isn't at all close to what I'm actually coding, just a good approximating example.) abstract class PersonID { public string m_Name; public int m_ID;
3
2859
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
2083
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 one if (s)he wants. I keep tables in a doubly-linked list using the nice TAILQ_* macros: http://www.openbsd.org/cgi-bin/man.cgi?query=queue
8
7208
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. the string has also to seem a random one and it cannot have an apparence of a sequence. My first approach is to do it with a decimal counter and find and use an encryption alghorithm that converts each 6 digit decimal number to a 6 digit...
12
28457
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 adding a unique order number to a customer order form. I have 4 stages to my order form. Stage 1 involves the user selecting a link based on what they want. The link then sets 2 variables. $type and $fault based on the link they have chosen.
3
6438
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 INDEX.PHP <?php print "<font face='verdana' size='1'>";
0
9384
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9973
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9790
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9779
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9645
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8645
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5069
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5247
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3742
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.