i have a php page with a voting form but before the user can vote i want to create a file with his ip address or see if it exists, all of this is for preventing that the user votes several time, but i can't put the script to work. i've tried cookies but i can't figure them out.
<html>
<head>
<title> omdb - oscar movies data base </title> </head>
<body bgcolor="#FFFFFF" text="#000000">
<div align="center">
<table width="825" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr valign="middle">
<td width="825" height="50" bgcolor="#CCCCCC"> <div align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="5"><b>Top
Winner Movies Voting List<font color="#CCCCCC">.</font></b></font></div></td>
</tr>
<tr>
<td height="400" valign="top"> <div align="left">
<p><font face="Verdana, Arial, Helvetica, sans-serif">Select your <strong>10</strong>
favorite movies from the list.</font></p>
<p>
<?php
$connection=mysql_connect("localhost","","");
if (!$connection) {
print ("problems connecting to Mysql server");
}
$sql="select * from movies order by votes desc";
$result = mysql_db_query ("omdb", $sql);
if ($result) {
$ficdest=explode(".",basename($PHP_SELF));
$ficdest=$ficdest[0].".dat";
if(file_exists($ficdest)) {
$user=fopen($ficdest, "r");
$old_votes=file($ficdest);
$votes=explode("|", $old_votes);
fclose($user);
}
$ip_hit=$REMOTE_ADDR;
$user=fopen($ficdest, "w");
fputs($user, "$ip_hit");
fclose($user);
}
else {
$new_user=fopen($ficdest, "w");
fputs($new_user, "$REMOTE_ADDR");
fclose($new_user);
}
if (!empty($envoi)) {
$vote=fopen($ficdest, "r");
$old_votes=file($ficdest);
$votes=explode("|", $old_votes);
fclose($vote);
if ($votes != $REMOTE_ADDR) {
$vote=fopen($ficdest, "w");
$new_votes=fputs($vote, "$ip_vote");
fclose($vote);
}
else { echo "<font face=Verdana size=2 color=red>You have already voted</font>"; }
$ip_vote=$REMOTE_ADDR;
$vote=fopen($ficdest, "w");
$new_votes=fputs($vote, "$ip_vote");
fclose($vote);
}
print ('<form method="post" action="vote.php">');
print ("<table width=\"75%\" align=center border=1 bordercolor=#CCCCCC>");
print ("<tr><td width=\"10%\" bgcolor=\"CCCCCC\"><font face=\"Verdana, Arial, Helvetica, sans-serif\">SELECT</font></td><td width=\"50%\" bgcolor=\"CCCCCC\"><font face=\"Verdana, Arial, Helvetica, sans-serif\">TITLE</font></td><td width=\"10%\" bgcolor=\"CCCCCC\"><font face=\"Verdana, Arial, Helvetica, sans-serif\">VOTES</font></td></tr>");
while ($regist=mysql_fetch_array($result)) {
$tit=$regist["title"];
$vot=$regist["votes"];
$id=$regist["id"];
print ("<tr><td><input type='checkbox' name='assign_name[]' value='" . $regist["id"] . "'></td><td><font face=\"Verdana, Arial, Helvetica, sans-serif\">$tit<font></td><td><font face=\"Verdana, Arial, Helvetica, sans-serif\">$vot</font></td></tr>");
}
echo "</table>";
echo '<p align="center"><input type="submit" value="Vote" />';
echo '</form>';
}else{
print ("there are no entries");
}
mysql_free_result ($result);
?>
</p>
</div></td>
</tr>
</table>
</div>
</body>
</html>
i hope anyone can help me with this and i thank you in advance.