Jump to content

Session - avoid double vote


eevan79

Recommended Posts

I want to avoid double vote using session, but cant make it to work. Here is my script:

 

<?php
$mode = $_GET[''mode''];
$voted = intval($_GET[''voted'']);

//vote 1 to 5
if(($voted < 1)||($voted>5)) die;
if ($mode=="vote")
{

//update mysql
mysql_query ("UPDATE fraze SET total = total+$voted, votes = votes+1, srednja = round(total/votes, 2) WHERE id = $id");
echo "<meta http-equiv=''refresh'' content=''0;URL=http://www.mysite.info/index.php?id=".$red[''id'']."''>"; 
}

?>

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/185238-session-avoid-double-vote/
Share on other sites

<?php
session_start();
if($_SESSION['voted']==1)
{
echo "Already voted";
exit 0;
}
   $mode = $_GET[''mode''];
   $voted = intval($_GET[''voted'']);
   
   //vote 1 to 5
   if(($voted < 1)||($voted>5)) die;
   if ($mode=="vote")
   {
      
   //update mysql
   mysql_query ("UPDATE fraze SET total = total+$voted, votes = votes+1, srednja = round(total/votes, 2) WHERE id = $id");
$_SESSION['voted']=1;
   echo "<meta http-equiv=''refresh'' content=''0;URL=http://www.mysite.info/index.php?id=".$red[''id'']."''>"; 
   }
            
   ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.