473,761 Members | 3,651 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1961
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('MYDIVI DER', $contents_of_fi le);
[/PHP]

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

[PHP]
if(in_array($_S ERVER['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.c om> 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.c om> 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
2023
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 by its members? (including identifying individual voters against a membership password list, keeping track of votes, customizing the ballot, and so on -- although massive security precautions are not required)
2
3060
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 why!!! Microsoft fix it!!!
1
2692
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
5731
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 browser? Please advise.
4
1761
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. Can somebody help in this.
4
6660
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 Visual Studio 2005. Best Regards, Luqman
5
21103
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
1460
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 image button. With caching turned on, the control remains "lame" since the control is only dynamically generated during the first access. My understanding is that page caching directive causes all page user controls to be implicitly cached as...
0
1336
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 something as the code follows in here using System;
0
9522
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
10111
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
9948
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...
0
9765
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
8770
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...
1
7327
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5364
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3866
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
3
2738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.