473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to I prevent a user from running a module twice (i.e. online voting) ?


I've got a voting script that's a little too simple. I can vote as as
many times as I can click on the link in my browser.

I'n not trying to write an official voting system but I would like to
do something as simple as catching the user's IP address and
remembering it for a time interval. That has it's own problems, but
it would at least prevent double clicks.

I can get the IP #, but how do I store it on a server? I can do a flat file
or something.

Any other suggestions or code are welcome.

I'm new to PHP.

Thanks.

--
a d y k e s @ p a n i x . c o m

Don't blame me. I voted for Gore.
Feb 6 '06 #1
5 1936
You could store it in a file yes, a MySQL backend would be better
though.

I assume you know how to append data to files, with this you can add IP
addresses with a divider (new line, tab, any character you like). You
can read that file during the processing of the poll and create an
array of IP's:

[PHP]
$voted = explode('MYDIVIDER', $contents_of_file);
[/PHP]

You can then check the current visitors IP against this array:

[PHP]
if(in_array($_SERVER['REMOTE_ADDR'], $voted)) {
die('You have already voted!');
{
[/PHP]

I hope that helps.

Feb 6 '06 #2
> I've got a voting script that's a little too simple. I can vote as as
many times as I can click on the link in my browser.


Store a cookie at the client side (use setcookie()) and check that to
see if the user has
already voted. Of course, this is fairly easy to bypass: just disable
cookies. You can store an IP on the server, but multiple people can
come from one IP address. If your site is not very busy, you can store
one IP: a user can vote multiple times, but has to wait till any other
user has voted.

Feb 6 '06 #3
>I've got a voting script that's a little too simple. I can vote as as
many times as I can click on the link in my browser.
Isn't that about the same as electronic voting in the United States?
I'n not trying to write an official voting system but I would like to
do something as simple as catching the user's IP address and
remembering it for a time interval. That has it's own problems, but
it would at least prevent double clicks.
Beware of false positives (different people in the same office
voting through a NAT gateway or web proxy that makes them all appear
to have the same IP) and false negatives (dialup user who gets a
different IP every time he dials up).
I can get the IP #, but how do I store it on a server? I can do a flat file
or something.


Flat files have their problems, like locking when you've got several
voters updating the flat file simultaneously. But you can use them.
Look at functions like fopen().

Think about using a database (e.g. MySQL) backend. It's easy to
write a query like:

select count(*) from votesdone where ip = '$ip' and
stamp > subdate(now(), interval 24 hour)

If it returns a number greater than 0, that IP has voted recently.
If it returns 0, it hasn't.

Databases are good at locking, so you can lock the table, check if
they already voted, if not record their vote, and unlock. Or use
transactions.

Gordon L. Burditt
Feb 6 '06 #4
d
"Al Dykes" <ad****@panix.com> wrote in message
news:ds**********@panix5.panix.com...

I've got a voting script that's a little too simple. I can vote as as
many times as I can click on the link in my browser.

I'n not trying to write an official voting system but I would like to
do something as simple as catching the user's IP address and
remembering it for a time interval. That has it's own problems, but
it would at least prevent double clicks.

I can get the IP #, but how do I store it on a server? I can do a flat
file
or something.

Any other suggestions or code are welcome.

I'm new to PHP.

Thanks.

Think how they do it in real life :) Make sure everyone who wants to vote
has a username/password - simply ask for that before voting, and then you
know if a user has already voted or not.

--
a d y k e s @ p a n i x . c o m

Don't blame me. I voted for Gore.

Feb 7 '06 #5
the simplest, unsecure way of doing it is to use cookies.
when a user votes, check if a cookie exist
if it does, he cannot vote
if it doesn't , he can vote
after the vote, write a cookie

problem is, the user can clear all cookies and vote again.
so, it all depends on how secure you need it to be.

Barry

d wrote:
"Al Dykes" <ad****@panix.com> wrote in message
news:ds**********@panix5.panix.com...
I've got a voting script that's a little too simple. I can vote as as
many times as I can click on the link in my browser.

I'n not trying to write an official voting system but I would like to
do something as simple as catching the user's IP address and
remembering it for a time interval. That has it's own problems, but
it would at least prevent double clicks.

I can get the IP #, but how do I store it on a server? I can do a flat
file
or something.

Any other suggestions or code are welcome.

I'm new to PHP.

Thanks.

Think how they do it in real life :) Make sure everyone who wants to vote
has a username/password - simply ask for that before voting, and then you
know if a user has already voted or not.



--
a d y k e s @ p a n i x . c o m

Don't blame me. I voted for Gore.


Feb 7 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: AES | last post by:
Can anyone point to software or HTML code (preferably shareware or modest cost, preferably Mac or PC based) that would permit a small organization to carry out a simple election with online voting...
2
by: magister | last post by:
Does smartnavigation on parent page make user controls page_load twice... Any fixes for this!!! Problem is when boss sees smartnavigation he likes but it causes lots of other bugs....why...
1
by: The Fox | last post by:
How to prevent user to add web reference to my web services? Can I add password to web services so that only the users who know the password can add a web reference? Thanks in advance.
1
by: User | last post by:
Hi, Are there ways to let browser forget about the previous submitted form data? Or prevent user from pressing F5 to submit the same form again Or prevent user from presising back on the...
4
neo008
by: neo008 | last post by:
Hi All, Can I prevent user to press cross button? I want to disable all three buttons for minimize, maximize and close for parent as well as child window. Is it possible? I'm using VB6. ...
4
by: Luqman | last post by:
How can I Prevent user from accessing any page directly without Login ? User should not be able to by pass the Login screen by typing the Url of any page directly. I am using ASP.Net 2.0 with...
5
by: alvintiow | last post by:
Hi, I intend to use barcode for input and prevent user to modify the barcode they scan, user are not allow to input the barcode number by keyboard. Please advise how to do this. Thanks.
0
by: helveticus | last post by:
I have a master/details configuration that includes multiple user controls. The details page is configured to cache data via VaryByCustom. This works fine. One of the user controls contains an...
0
by: Appyks | last post by:
How Do I prevent User from Locking the System? Obviously I can set following Windows registry value But it doesn’t serve my propose "DisableLockWorkstation"=dword:00000001 I need...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
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...

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.