|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
Quote:
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. |
|
#5
|
|||
|
|||
|
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? |
|
#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? |
|
#7
|
|||
|
|||
|
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. ![]() |
|
#8
|
|||
|
|||
|
haha,..it's ok,...not understanding IS ok
![]() heres what I would. This is the Code on each page with a poll PHP Code:
This is directly after the vote has been cast. PHP Code:
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. |
|
#9
|
|||
|
|||
|
thanks a lot you've been most helpful.
now that i think i got it i'll give it a shot. |
|
#10
|
|||
|
|||
|
great
![]() Just remember,....when coding, there is most likely more then one way to do what you want it to do ![]() |
|
#11
|
|||
|
|||
|
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. |
|
#12
|
|||
|
|||
|
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? |
|
#13
|
|||
|
|||
|
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:
tell me if this is it? and what the hell the $votes Meen? |
|
#14
|
|||
|
|||
|
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:
PROCESS.PHP PHP Code:
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. ![]() |
|
#15
|
|||
|
|||
![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > cookies |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |