Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.