Forum Moderators: coopster

Message Too Old, No Replies

Guest user gives only one vote.How?

vote

         

winpeace

11:56 am on Mar 5, 2008 (gmt 0)

10+ Year Member



I use component for joomla.This component in vote system.And for example one guest user give continuous vote any article(one ip).But I want one guest user give one vote(not 2,3,...votes).

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.

jatar_k

2:25 pm on Mar 5, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



the trouble is always how to uniquely identify someone that isn't logged in

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.

winpeace

2:29 pm on Mar 5, 2008 (gmt 0)

10+ Year Member



sorry
how to control cookies?
whats code I add

vfoo

6:08 pm on Mar 6, 2008 (gmt 0)

10+ Year Member




<?php
#somewhere after your user votes:
setcookie("HasVoted", "1", time()+3600);

#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

winpeace

8:48 am on Mar 17, 2008 (gmt 0)

10+ Year Member



I am new user php.So I am sorry
I found this $_SERVER["REMOTE_ADDR"]

How to add this code in my codes(I don't know how add)

jatar_k

1:52 pm on Mar 17, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



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

penders

5:28 pm on Mar 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Just a thought... if you are allowing a guest to vote and recording that they have voted by way of a cookie then I would have thought that you'd also need to make sure that cookies were in fact enabled first - otherwise, with cookies disabled for the domain, the guest user could also keep on voting...?

winpeace

8:19 pm on Mar 18, 2008 (gmt 0)

10+ Year Member




I add this.Nothing is change:(:(

<?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]

penders

10:29 am on Mar 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



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.