Jump to content

Simple Counter


PeterPopper

Recommended Posts

There are many counter examples out there. You best just look at them. As for the "winnner" code, You can have a simple IF/ELSE statement on the code that will propagate the visit to the database.

 

But as obvious, Record IP's per visits, so no one person can refresh the page 200 times and get it.

Link to comment
https://forums.phpfreaks.com/topic/198061-simple-counter/#findComment-1039230
Share on other sites

CREATE TABLE ips (id auto_increment primary key, ip char(32))

ALTER TABLE ips ADD UNIQUE ip

 

//the 32 characters is for ipv6

 

$ip=getenv(REMOTE_ADDR)

 

INSERT IGNORE INTO ips (ip) VALUE ($ip)

 

Now you can:

 

SELECT id ORDER by id desc limit 1;

 

to get the current count.

 

Do the insert statement first, that way if they are a unique visitor, they will increment the value, Now, you need a table that will define which winners are given away.  Here is the scneario you need to think of:

 

visitor 200 just collected his prize and I visit the site but am not a unique visitor, I get a prize too because of the %200 issue.  So have a table that If winner, you query to see if the prize is given away (so the table will have something like counter, email and counter would get 200, 400, etc but you need to update the table AS SOON as you determine winner, not after you collect email info.

 

 

Link to comment
https://forums.phpfreaks.com/topic/198061-simple-counter/#findComment-1039307
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.