View Full Version : Guest user gives only one vote.How?
winpeace
03-05-2008, 11:41 AM
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. And product book component all files is in attachment
winpeace
03-07-2008, 09:52 PM
help :(
Leafy
03-07-2008, 10:32 PM
In most environments,
$_SERVER["REMOTE_ADDR"]
is the superglobal for the user's IP address. Try using a field for each image and have a CSV of their IP addresses.
winpeace
03-08-2008, 11:44 AM
where I add this code?
$_SERVER["REMOTE_ADDR"]
winpeace
03-15-2008, 12:51 PM
don't solved
winpeace
03-17-2008, 08:49 AM
I am new user php.So I am sorry
thanks this code $_SERVER["REMOTE_ADDR"]
but;
How to add this code in my codes(I don't know how add)
city_coder
03-17-2008, 11:16 AM
Ok il try and help as you asked so kindly
This bit of code will be at the top of your page that displays the voting.
<?
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
}
?>
and on your page that receives the vote you would have
<?
//do whatever you normally do with it
//save using cookie, cookie will expire after 24hrs, no point saving it for longer as the users ip will change if they turn their pc on and off in between.
$user_ip = $_SERVER['REMOTE_ADDR'];
setcookie('guest_cookie', '$user_ip', time() + (60*60*24));
?>
Feel free to correct me anyone as iv just written it here and now without testing it, it will probably have something wrong with it or it could be written better.
winpeace
03-18-2008, 06:55 PM
it is not working.
always come white page when vote product
city_coder
03-18-2008, 07:33 PM
You always get a white page when you come to vote?...Sorry iv just noticed a stupid mistake in my code
On the voting page put this...its exactly the same as before only there is an extra bracket.
<?
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
}
?>
Try that, hopefully that will work now
winpeace
03-18-2008, 09:00 PM
No ıt isn't solved
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>";
?>
example link (http://www.design-cars.com/component/option,com_productbook/Itemid,39/func,detail/id,27/)
city_coder
03-18-2008, 10:02 PM
Right i really dont know your code that well, the way you do it is quite different to most and there is a script alert that i dont know anything about so i cant help with that bit.... when i said the '//display voting system, whatever it is ' you have to put the code that displays the system in that part of the code.
If you go into your browser and see if your cookie is set to make sure the first bit of code is working and then check that your IP is that value that is being stored.
My suggestion is to take out your code bit by bit until you get to stage of it working, then build the other bits in and see where it crashes.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.