Forum Moderators: coopster
vote.php is this;
<?php defined ('_VALID_MOS') or die( 'Direct Access to this location is not allowed.' );
$database->setQuery( "SELECT imgvotes, imgvotesum FROM #__productbook WHERE id = '$id'" );
$result1=$database->query();
list( $imgvotes, $imgvotesum )=mysql_fetch_row( $result1 );
$imgvotes++;
$imgvotesum=$imgvotesum + $imgvote;
$database->setQuery( "UPDATE #__productbook SET imgvotes='$imgvotes', imgvotesum='$imgvotesum' WHERE id=$id" );
$database->query();
echo "<script> alert('".$PRODUBK->PRODUBK_0031."');
document.location.href='".sefRelToAbs("index.php?option=com_productbook&func=detail&Itemid=$Itemid&id=$id")."';</script>";
?>
Note:My english is bad. sorry.
by IP? no, too many people share IPs
so you should drop a cookie on there, check for that cookie, aand if the cookie does not exist then let them vote. They could easily delete this cookie though.
otherwise you only let people vote when logged in and that is easily tracked and controlled.
#next time the user tries to vote:
if( $_COOKIE["HasVoted"] == "1"){
echo "No more voting for you";
} else {
#go ahead and let em vote
}
?>
Keep in mind that a user can always clear their cookies and vote as much as they want. to get around that you need a login system
hth
vfoo
<?php
if(isset($_COOKIE['guest_cookie'])) {
$cookie_ip = $_COOKIE['guest_cookie'];
$user_ip = $_SERVER['REMOTE_ADDR'];
if(strcmp($cookie_ip == $user_ip)) {
echo "You have already voted on this topic";
} else {
//display voting system, whatever it is
}
} else {
//display voting system, whatever it is
} defined ('_VALID_MOS') or die( 'Direct Access to this location is not allowed.' );
$database->setQuery( "SELECT imgvotes, imgvotesum FROM #__productbook WHERE id = '$id'" );
$result1=$database->query();
list( $imgvotes, $imgvotesum )=mysql_fetch_row( $result1 );
$imgvotes++;
$imgvotesum=$imgvotesum + $imgvote;
$database->setQuery( "UPDATE #__productbook SET imgvotes='$imgvotes', imgvotesum='$imgvotesum' WHERE id=$id" );
$database->query();
echo "<script> alert('".$PRODUBK->PRODUBK_0031."');
document.location.href='".sefRelToAbs("index.php?option=com_productbook&func=detail&Itemid=$Itemid&id=$id")."';</script>";
?>
[edited by: coopster at 8:47 pm (utc) on Mar. 18, 2008]
[edit reason] no urls please TOS [webmasterworld.com] [/edit]
if(isset($_COOKIE['guest_cookie'])) {
$cookie_ip = $_COOKIE['guest_cookie'];
$user_ip = $_SERVER['REMOTE_ADDR'];
if ($cookie_ip == $user_ip) {
echo "You have already voted on this topic";
} else {
//display voting system, whatever it is
}
} else {
//display voting system, whatever it is
} Ok, but where it says "//display voting system, whatever it is", that is where you need to place your voting system code. At the moment that new bit of code does nothing (as you say, "Nothing is change"). Also I removed your strcmp() [uk.php.net] function call as it was syntactically incorrect the way you had it.
Also, as jatar_k states above:
that would be the user IP, more than one user can have the same IP so it isn't the best thing for deciding what is a unique user
Also, you need to call setcookie() to set your 'guest_cookie' after the user has voted. You may be doing this, but I don't see it above.