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
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'']."''>"; 
   }
            
   ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.