iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Database Discussion Forum This is the place to find help resolving those nagging questions you have about implementing and using all kinds of databases. Need help writing a query? Need an opinion on Oracle? Post here!

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-26-2009, 11:31 AM
WebProWorld Member
 
Join Date: Aug 2003
Location: Jersey City, NJ
Posts: 74
jazzmatazz2005 RepRank 0
Question If, Else and Array's

I have a voting script on one of my sites and it works fine, but i want to block people from multiple voting.
i figured the best way was to record the ip address and then block that ip from voting for a particular person again.

This is what part the code on the vote process page looks like:

// get stuff from form

$ips = $_GET["ip"];
$who = $_GET["manme"];
$wherefromwas = $_GET["whereami"];

// Make a MySQL Connection


$link = mysql_connect("localhost","root","");
mysql_select_db("unrated1",$link);
$query = "SELECT * FROM votes WHERE votes.mname = '$who' ";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
//echo $row['mname']. " - ". $row['ip'];
//echo "<br />";
if ($row['ip'] == $ips ){header("refresh: 0; url=$wherefromwas"); }

}

basically this is what i want this to do:

let say you want to vote for me.
it should get all of the ip's (other votes for me) and check to see if you have voted for me before
if so then return you back to the page. (don't allow/record the vote)

if not it should continue to process the vote which is basically a few more if's and else to make sure the the voting form is completed and record the vote.
i can't get it to work properly.
it records a new vote every time.
what am i doing wrong here?

If you want to see this in action send me a message and ill send you the link and show you all the vote process code
__________________
It's better to do business with me than against me!
Reply With Quote
  #2 (permalink)  
Old 06-26-2009, 01:54 PM
wige's Avatar
Moderator
WebProWorld Moderator
 
Join Date: Jun 2006
Location: United States
Posts: 2,648
wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9
Default Re: If, Else and Array's

An easier approach might be to simply make the IP address column unique, then try to save the vote? If $result is true, the vote is from a new IP, otherwise the vote is from an IP that already voted (and thus the vote would not be added to the database).

Of course, either way this will be less than foolproof, as dial up users get new addresses with every connection, and there are commands that broadband users can use to change their IP addresses. It might give better results to require registration before voting, requesting an ISP e-mail address and not allowing free e-mail addresses in order to register to vote.
__________________
The best way to learn anything, is to question everything.
Reply With Quote
  #3 (permalink)  
Old 06-26-2009, 02:33 PM
WebProWorld Member
 
Join Date: Aug 2003
Location: Jersey City, NJ
Posts: 74
jazzmatazz2005 RepRank 0
Default Re: If, Else and Array's

Thanks wige.
I thought about that. The votes are really just for entertainment but i want it to be somewhat fair.
if a user does get a new ip address that fine. Thats just another unique vote.

I have looked around and made some changes to the code


$link = mysql_connect("localhost","root","");
mysql_select_db("unrated1",$link);
$query = "SELECT * FROM votes WHERE votes.mname = '$who' ";
$result = mysql_query($query) or die(mysql_error());
//while($row = mysql_fetch_array($result)){

if ($row['ip'] == $ips)
{
header("refresh: 0; url=nope.php");
}
else
{

while($row = mysql_fetch_array($result))
{
header("refresh: 0; url=yes.php");





}}

i though this would work but no.

Ill check into making the IP column unique. Good Idea.
__________________
It's better to do business with me than against me!

Last edited by jazzmatazz2005; 06-26-2009 at 02:36 PM.
Reply With Quote
  #4 (permalink)  
Old 06-26-2009, 02:51 PM
kgun's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,678
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
Default Re: If, Else and Array's

A delicate problem. There should be better solutions that logging Ip's.
  1. I once tried to fool a Norwegian voting site. It was impossible, even going via a proxy server. Should like to know that programmer.
  2. What about using OpenID? You can of course have more than one OpenID, but it is more complicated than going from computer to computer with different Ip's.
Reply With Quote
  #5 (permalink)  
Old 06-26-2009, 02:58 PM
williamc's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: Jul 2003
Location: GoogleVille
Posts: 1,585
williamc RepRank 7williamc RepRank 7williamc RepRank 7williamc RepRank 7williamc RepRank 7williamc RepRank 7williamc RepRank 7williamc RepRank 7williamc RepRank 7
Default Re: If, Else and Array's

I would suggest coupling the use of persistant sessions and cookies into the mix as well as IP's. That would also cut a decent % off the invalid vote counts.
__________________
William Cross
Expert Search Engine Optimization
Reply With Quote
  #6 (permalink)  
Old 06-26-2009, 03:15 PM
kgun's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,678
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
Default Re: If, Else and Array's

If you know opera:config (put it in the address field) you can change default settings to surf "almost" invisible.

Last edited by kgun; 06-26-2009 at 03:21 PM.
Reply With Quote
  #7 (permalink)  
Old 06-26-2009, 03:26 PM
WebProWorld Member
 
Join Date: Aug 2003
Location: Jersey City, NJ
Posts: 74
jazzmatazz2005 RepRank 0
Default Re: If, Else and Array's

thanks williamc and kgun. i dont want anything to complicated. like i said its only for entertainment.

maybe i wasnt clear with what my voting form does.

for every person thats active (over 400 so far)
there are three categories that you vote on.
in all three categories you basically vote 1-5

in the process page it checks to make sure you filled in all three categories and saves all the information along with your IP.

In my simple code i thought you could get all the votes for "a" active person into an arrow and check to see if the user has voted for this active person before.

if

so return the user back to the page and save the save

else

save all the information then return the user back to the page where they can can then move on to the next person and the process starts all over again.

I tried making the IP column unique but now it dosn't allow anymore votes from the same person at all.
when your vote for 1 person thats it, you cant vote anymore. Thats no fun
there are over 400 people to vote on.
__________________
It's better to do business with me than against me!
Reply With Quote
  #8 (permalink)  
Old 06-26-2009, 03:37 PM
wige's Avatar
Moderator
WebProWorld Moderator
 
Join Date: Jun 2006
Location: United States
Posts: 2,648
wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9
Default Re: If, Else and Array's

I agree with kgun and william, you will probably get something more effective using cookies.

As far as allowing multiple votes, the only mechanism I can think of is to do a count, then based on that count determine whether or not to add the new vote to the list.

"SELECT COUNT(*) FROM votes WHERE ip = '".$_SERVER['REMOTE_ADDR']."' AND votes.mname = '$who'"

As long as the count is zero, this user has not voted for this person yet.
__________________
The best way to learn anything, is to question everything.
Reply With Quote
  #9 (permalink)  
Old 06-26-2009, 06:38 PM
WebProWorld Member
 
Join Date: Aug 2003
Location: Jersey City, NJ
Posts: 74
jazzmatazz2005 RepRank 0
Default Re: If, Else and Array's

thanks wige....ill try that. is sounds like it should wok
__________________
It's better to do business with me than against me!
Reply With Quote
  #10 (permalink)  
Old 06-26-2009, 09:33 PM
WebProWorld Member
 
Join Date: Jul 2003
Location: Philadelphia
Posts: 82
dean RepRank 1
Default Re: If, Else and Array's

This might be nothing, but I noticed that the GET array variable you're assigning to $who is $_GET["manme"] and in your select statement you're comparing to a database field named mname. Is this a typo?
Reply With Quote
  #11 (permalink)  
Old 06-26-2009, 09:35 PM
Uncle Dog's Avatar
WebProWorld Pro
 
Join Date: Apr 2008
Location: Scotland
Posts: 254
Uncle Dog RepRank 5Uncle Dog RepRank 5Uncle Dog RepRank 5Uncle Dog RepRank 5Uncle Dog RepRank 5Uncle Dog RepRank 5
Default Re: If, Else and Array's

A quick glance makes me think that unless the first IP in the array matches the one for the new voter then it will drop through, without checking the rest, and be accepted.

Try

While loop stepping through existing ips {

if ip match {
set bad flag
drop out of while loop
}

}

if bad flag set {
bad vote
} else {
thanks
}

Last edited by Uncle Dog; 06-26-2009 at 09:43 PM.
Reply With Quote
  #12 (permalink)  
Old 07-01-2009, 04:39 PM
mikeewart's Avatar
WebProWorld New Member
 
Join Date: Jan 2004
Posts: 11
mikeewart RepRank 1
Default Re: If, Else and Array's

Another thing to consider is multiple users voting from the same company network/ school, etc. The IP limit would most likely block out the second person. I agree that cookies would work better
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Database Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 01:31 AM.



Search Engine Optimization by vBSEO 3.3.0