Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Guest user gives only one vote.How?

  1. #1
    Join Date
    Nov 2006
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Guest user gives only one vote.How?

    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 Code:
    <?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

  2. #2
    Join Date
    Nov 2006
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    help

  3. #3
    Join Date
    Jan 2008
    Posts
    32
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    In most environments,
    PHP Code:
    $_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.

  4. #4
    Join Date
    Nov 2006
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    where I add this code?
    Code:
    $_SERVER["REMOTE_ADDR"]

  5. #5
    Join Date
    Nov 2006
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    don't solved

  6. #6
    Join Date
    Nov 2006
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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)

  7. #7
    Join Date
    Feb 2008
    Location
    Coventry
    Posts
    103
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default

    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.
    Code:
    <?
    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

    Code:
    <?
    //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.
    The important thing is not to stop questioning. Curiosity has its own reason for existing.

  8. #8
    Join Date
    Nov 2006
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    it is not working.
    always come white page when vote product

  9. #9
    Join Date
    Feb 2008
    Location
    Coventry
    Posts
    103
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default

    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.
    Code:
    <?
    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
    The important thing is not to stop questioning. Curiosity has its own reason for existing.

  10. #10
    Join Date
    Nov 2006
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    No ıt isn't solved

    I add this.Nothing is change

    PHP Code:
    <?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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •