here is the basic idea :
have a form on a page which allows the user to vote and let the form submit to the same page.
first time the page is loaded , check for the sesion variable, its set that means user has voted, if not first vote.
if first vote then set the session variable , so that when user submits the vote the session variable is also submitted.
now if session variable is present, that means its a vote, input values to database, update session variable with poll id. the enxt time you check if session var has poll id in it
well if the user closes the browser then he can vote again, so u can also log the user_id .
it seems a bit confusing but i hope i helps
here is a sample code
<?php
session_start();
if(isSet($first_visit)){
session_register($first_visit);
}
if (isSet($vote)){
$error = 0;
if($vote > 0 && $vote < 11){
$error = 0;
}else{
$error = 1;
}
if(!(isSet($vote_id)){
$error = 1;
}
}else{
$error = 1;
}
if ($error == 1){//either not voted or vote value greater than 10
?>
<html>
<head>
<title>Rate This File!</title>
</head>
<body>
<table>
<tr><td><b>Rate This File!</b></td></tr>
</table>
<center>
<form method="post" action="<?php print($PHP_SELF); ?>">
<input type="hidden" name="vote_id" value="<?php print($asset_id); ?>">
<select name="vote" size="1">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
</select> <input type="submit" value="Rate It!">
</form>
<br>
</center>
</body>
</html>
<?php
}else{
session_start();
$vote_check_id = $vote_id;
$msg = "";
if(isSet($first_visit)){
if(strstr($first_visit,$vote_check_id)){
$msg = "voted for this poll before";
$error = 1;
}else{
$msg = "voted before for another poll<br>";
$error = 0;
}
}else{
$msg = "never voted before..<br>";
$error = 0;
}
$first_visit = $first_visit."|".$vote_check_id;
session_register('first_visit');
/*
write code to insert $vote_id and $vote into database.
*/
session_register('first_visit',$vote_check_id);
/* GOOD VOTE
print($msg);
*/
/* redirect user to a thank you page to prevent them for refreshing the page and voting repeatedly
even though the error checking takes care of duplicate votes
*/
header("Location:thank_you_page.php?error=$error");
exit;
}else{
/* BAD VOTE
print($msg);
*/
header("Location:thank_you_page.php?error=$error");
/* redirect user to a thank you page to prevent them for refreshing the page and voting repeatedly
even though the error checking takes care of duplicate votes
*/
}
}
?>
i have not checked the code for syntax so its just to give u a rough idea of how to proceed