The first line of defense is a cookie.
Basically, you set a cookie on your computer and turn off voting if it is present.
setcookie('cookiename', 'voted=1');
if(isset($_COOKIE['cookiename']) && $_COOKIE['cookiename'] = "voted=1")
{
}
This will save you from calling the database, which may be required to verify their voting. It is a good idea to keep this in place because it is like caching: the fewer database accesses, the better.
- IP. IP- , .
mysql_query('INSERT INTO TABLE (`IP_ADDR`, `TIME`) VALUES("'.$_SERVER['REMOTE_ADDR'].'", "'.time().'")');
// and later
$results = mysql_query('SELECT IP_ADDR FROM TABLE WHERE IP_ADDR="'.$_SERVER['REMOTE_ADDR'].'"');
if(mysql_num_rows($results) != 0)
{
// error
}
script
if(isset($_COOKIE['cookiename']) && $_COOKIE['cookiename'] = "voted=1")
{
die("You have voted recently.");
}
$results = mysql_query('SELECT IP_ADDR FROM TABLE WHERE IP_ADDR="'.$_SERVER['REMOTE_ADDR'].'"');
if(mysql_num_rows($results) != 0)
{
die("You have voted recently");
}
vote($_GET['vote']);
setcookie('cookiename', 'voted=1');
mysql_query('INSERT INTO TABLE (`IP_ADDR`, `TIME`) VALUES("'.$_SERVER['REMOTE_ADDR'].'", "'.time().'")');
.., .