Photo Voting - need help

Discussion in 'PHP' started by r1919, Aug 23, 2008.

  1. #1
    Hello,

    I have a problem, with photo voting.

    I have an photo album and every photo have a voting pole (+ or -).
    I want that a user can vote a photo only one tine in an hour.

    I know that can be done with cookies but i don't know how.

    setcookie("votecookie", "imageID", time()+3600);
    this is working but only for a single photo. I need to create an array to store all votes.

    Anyone knows how?
    Thank you for your help.
     
    r1919, Aug 23, 2008 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    There are 2 ways of solving this.

    1. Check the IP address from previous vote on imageID and if vote is less then 3600 UNIX_TIMESTAMP seconds before current time, don't add vote and give error.
    2. create a cookie named like this votecookieIMAGEID

    
    setcookie("votecookie" . imageID, "checked", time()+3600);
    
    Code (markup):
     
    EricBruggema, Aug 23, 2008 IP
  3. r1919

    r1919 Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    And for every vote it will be created a different cookie?
    it is not possible to create a cookie with all votes?
     
    r1919, Aug 23, 2008 IP
  4. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #4
    then you need to save an array to the cookie (SERIALIZE) but if you want real security i would not go for the cookie but the IP address
     
    EricBruggema, Aug 23, 2008 IP
  5. MCJim

    MCJim Peon

    Messages:
    163
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    IP addresses can be switched via dynamic IPs or proxies. Cookies can be deleted. If you absolutely don't want vote spamming to happen, you could make user registration. If it doesn't bother you that much, I would just use the IP method.
     
    MCJim, Aug 23, 2008 IP