General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old January 8th, 2003, 04:41 PM
itworks itworks is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Internet
Posts: 12 itworks User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
cookies

i have a section in my site which is a list of all entries from a database and the user can vote in 10 of them. this is working fine but i must have some kind of protection against people who want to vote several times.

this section is composed by two scripts, TOP.PHP and VOTE.PHP.
the first one is the form and the second processes the votes.

so what i need is a cookie, right? the problem is that i don't know anything about them, how to set them and where to put it (which of the scripts).

can anyone help me with this? i'm very new in php.

thanks in advance

Reply With Quote
  #2  
Old January 8th, 2003, 05:30 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
well,....you could set a cookie that sets the ID of the voted item, the IP of that user and maybe a timestamp?

Would I would do is set the cookie after the vote has been processed. That way they can't vote on the same one twice.
__________________
-- Jason

Reply With Quote
  #3  
Old January 8th, 2003, 05:52 PM
itworks itworks is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Internet
Posts: 12 itworks User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
setting the cookie with the ID of the voted item would allow the user the vote on another items, wouldn't it?!

is that the better way to do it?

when you say that the best way should be to set the cookie after the vote has been processed where do you meen? shouldn't be the cookie setted before any html output?

sorry but i'm just so confused. i never used cookies.

Reply With Quote
  #4  
Old January 8th, 2003, 08:07 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
Quote:
Originally posted by itworks
setting the cookie with the ID of the voted item would allow the user the vote on another items, wouldn't it?!


Yes it would, but I thought thats what you wanted?

What I meant by the other part was. When a user votes, you insert the casted vote into the database and set set the cookie after that, before any html gets output.

You may need to use ob_start(); and ob_end_flush(); to control the output buffering.

Reply With Quote
  #5  
Old January 9th, 2003, 09:13 AM
itworks itworks is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Internet
Posts: 12 itworks User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
i don't get it! this was supposed to be easy and everytime i'm more confused.

could you tell me in simple steps HOW WOULD YOU DO IT?

Reply With Quote
  #6  
Old January 9th, 2003, 09:25 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
wow wow wow there buddy, I am only trying to help. I am sorry if I was confusing you.

How would I do it? Well it depends on a number of things.

So first off,...

you have 10 things to vote on. They can only vote on 10 correct?

Well then here is what I would do, but keep in mind if people have cookies disabled, then there is nothing to stop them from casting multiple votes.

ok, here are the steps I would take.

1.) User Votes
2.) Insert User Vote into Database
3.) Set Cookie with the ID of that particular poll.
With this, I would setup my code so that I have one entry in my cookie and seperate them with a ","
So lets say I vote on Item 1, 2, 5 and 8 my cookie entry would look like 1,2,5,8
Then in your code you can perform your checks to see if they have or have not voted.


--------------------------------------------------------------------------------

Another way to do it is to setup a reference table in your db and each time a user votes, you add an entry to the reference table with the persons userID, and the poll ID.

Make sense?

Reply With Quote
  #7  
Old January 9th, 2003, 10:10 AM
itworks itworks is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Internet
Posts: 12 itworks User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
don't get me wrong, i wasn't mad at you, i was mad at me for not understanding.

now i see what you meen in the theory. i'm sorry if i didn't explain better but the part where i need help is that i need two codes, one for setting the cookie and other for checking if it is a cookie when the user wants to vote, right?

if so, my problem is where to insert those codes in my 2 existing scripts?

i'm sorry for being a pain in the ass.

Reply With Quote
  #8  
Old January 9th, 2003, 10:31 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
haha,..it's ok,...not understanding IS ok


heres what I would.

This is the Code on each page with a poll

PHP Code:
<?php

if($_GET['poll'] && isset($_COOKIE['polls']))
{
    
$polls explode(","$_COOKIE['polls']);
    
/* 
        Do a Loop to determine if one of the keys data from the cookie
        matchs the $_GET['poll'] ID
        
        If there is a match, Tell the user he has already voted.
        else let him vote.
    */
}

?>



This is directly after the vote has been cast.

PHP Code:
 $voted_polls $_COOKIE['poll'];
$voted_polls .= "," $_GET['poll'];

setcookie("polls",$voted_polls,"3600","/",".domain.com"); 


This make sense?

Keep in mind this code is verrrry 'looose' lol you will need to take what you can from this and work it some

Last edited by Taelo : January 9th, 2003 at 11:03 AM.

Reply With Quote
  #9  
Old January 9th, 2003, 11:38 AM
itworks itworks is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Internet
Posts: 12 itworks User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanks a lot you've been most helpful.

now that i think i got it i'll give it a shot.

Reply With Quote
  #10  
Old January 9th, 2003, 11:52 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
great

Just remember,....when coding, there is most likely more then one way to do what you want it to do

Reply With Quote
  #11  
Old January 9th, 2003, 06:11 PM
itworks itworks is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Internet
Posts: 12 itworks User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
i've try to make it work but has i was implementing the code i realized that it was going in a much more complicated path than the one i need.

i just need

1st - to check if the is a cookie (no need to check any more, no variables, not the items that were selected, just a certain cookie).
2nd - if the isn't, do the work and set a cookie.
3rd - if there is, send a message telling the user he already voted.

as simple as this may seem, i don't know how to do it

i'm not asking you to give the code, but if you can, please just point me in the right way to a good tutorial or example.

best regards.

Reply With Quote
  #12  
Old January 9th, 2003, 09:29 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
that is essentially what I have givin you in my previous post. It will take a little more work to get it into a useable fashion, but it should be pretty straight forward from this point.

Maybe Ben or someone has another suggestion?

Reply With Quote
  #13  
Old January 10th, 2003, 04:38 AM
itworks itworks is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Internet
Posts: 12 itworks User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
as i mentioned before i have two scripts one with the voting form and another that processes the form.

tell me if i'm wrong but isn't this how it should work, kind of?

PHP Code:
if(isset($votecookie)) {
if (
$votes != $votecookie) {
}
}
setcookie("votecookie, $votes, 3600);
/* here goes the form script i have
}else{
echo ("
you have already voted");



tell me if this is it? and what the hell the $votes Meen?

Reply With Quote
  #14  
Old January 10th, 2003, 07:32 AM
itworks itworks is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Internet
Posts: 12 itworks User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
i solved it!

thanks everyone for your help you've been more then buddies to me.

i've solved it the most easier way you can imagine.

FORM.PHP
PHP Code:
<?php
/* here goes the connection with the database */
/* if it goes ok */
if (!isset($votecookie)) {
/* displays the form and allows the user to vote */
}else{
print (
"You have already voted!");
}
?>


PROCESS.PHP
PHP Code:
<?php
$expire
=mktime(0,0,0,1,1,2004);
$value=1;
setcookie('votecookie'$value$expire);
?>
<?php
/* here goes the connection with the database */
/* if it goes ok */
if (!isset($votecookie)) {
/* makes the changes in the db and displays the results */
}else{
print (
"You have already voted!");
}
?>


maybe i confused you all, but what i wanted was as simple as this, no need to do a loop to check the cookie values.

thanks.

Reply With Quote
  #15  
Old January 10th, 2003, 09:55 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > cookies


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread