从cookie投票5次

问题描述:

i need to allow vote from cookie 5 times. Set IP to DB i can't do, because people sit in network with same remote adress.

One time i check like this:

if( $dif_cookies == 1 ) //from DB
        if($_COOKIE["m_questioning3-$external_id"] == $external_id) {
            $q_show_status = 3;   
        } 

But i need allow 5 times, how? thank you

我需要允许cookie投票5次。 将IP设置为DB我无法做到,因为人们坐在具有相同远程地址的网络中。 p>

有一次我这样检查: p>

  if($ dif_cookies == 1)//来自DB 
 if($ _ COOKIE [“m_questioning3- $ external_id”] == $ external_id){
 $ q_show_status = 3;  
} 
  code>  pre> 
 
 

但是我需要允许5次,怎么样? 谢谢 p> div>

Dear Haroldas,

    if(!isset($_COOKIE["m_questioning3-$external_id"])){
          $_COOKIE["m_questioning3-$external_id"]["count"] = 1;
    }else{
          $_COOKIE["m_questioning3-$external_id"]["count"]++;
    }

    if($_COOKIE["m_questioning3-$external_id"]["count"]<=5){
          your work
    }

it will work. Please check it.

thanks for help, but i found solution himself:

im sending post after vote submit and set the cookie:

if (isset($_COOKIE["m_questioning3-$form_id"])) {
    if ($_COOKIE["m_questioning3-$form_id"] <= 5)
        setcookie("m_questioning3-$form_id", (int)$_COOKIE["m_questioning3-$form_id"]+1);
} else {
    setcookie("m_questioning3-$form_id", 1);
}

in form cheking the cookie value:

if ( $dif_cookies == 1 )
    if($_COOKIE["m_questioning3-$external_id"] >= 5) {
        $q_show_status = 3;  
} else {           
    switch ($q_form_type) {
        //... bla bla bla ...
}