hit counter and more

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

hit counter and more

Post by Vegan »

I have occasionally looked at ideas for my sites and other projects

Code: Select all

 CREATE TABLE `counter` ( `counter` INT( 20 ) NOT NULL );
 INSERT INTO counter VALUES (0); 
so now that I have a table in my database I was thinking, what can I do....

Code: Select all

 // Connects to your Database 
 mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error()); 
 mysql_select_db("Database_Name") or die(mysql_error()); 
so with the database I was wondering if I could leverage it better?

Code: Select all

mysql_query("UPDATE counter SET counter = counter + 1");
seems obvious, then....

Code: Select all

$count = mysql_fetch_row(mysql_query("SELECT counter FROM counter"));
so then I guess....

Code: Select all

echo $count
so given the power of PHP and SQL, can I do better?

Google seems to be able to do more with their hit counter, can I expand on this crude design, how about a row for unique hits
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: hit counter and more

Post by requinix »

What is the problem you are trying to solve?
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: hit counter and more

Post by Vegan »

I was wondering, how hard would it be to track unique users for the day?
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
benanamen
Forum Newbie
Posts: 18
Joined: Sun Nov 15, 2015 11:57 am

Re: hit counter and more

Post by benanamen »

Aside from your question, the code you posted is obsolete and has been completely removed from Php. You need to use PDO https://phpdelusions.net/pdo.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: hit counter and more

Post by Christopher »

Vegan wrote:I was wondering, how hard would it be to track unique users for the day?
There is software that does web server's log analysis and generates statistics like unique users. You can also use something like Google Analytics that does the same thing by adding Javascript to your website.
(#10850)
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: hit counter and more

Post by Vegan »

I use Google now, but I was looking to build countermeasures to click bots etc for an ad manager
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
Post Reply