English 中文(简体)
如何修正 IP 投票?
原标题:How to fix IP-Based voting?
  • 时间:2012-05-24 19:44:03
  •  标签:
  • php

我拥有IP投票码, 但问题是当我用电脑投票时(用同一个网络连上互联网),

以下是代码:

global $wpdb;
$post_ID = $_POST[ id ];
$ip = $_SERVER[ REMOTE_ADDR ];
$irt_textOnclick = get_option( irt_textOnclick );
$recommend = get_post_meta($post_ID,  _recommended , true);

if($post_ID !=   ) {
    $voteStatusByIp = $wpdb->get_var("SELECT COUNT(*) FROM ".$wpdb->prefix."irecommendthis_votes WHERE post_id =  $post_ID  AND ip =  $ip ");

    if (!isset($_COOKIE[ recommended- .$post_ID]) && $voteStatusByIp == 0) {
        $recommendNew = $recommend + 1;
        update_post_meta($post_ID,  _recommended , $recommendNew);

        setcookie( recommended- .$post_ID, time(), time()+3600*24*365,  / );
        $wpdb->query("INSERT INTO ".$wpdb->prefix."irecommendthis_votes VALUES (  , NOW(),  $post_ID ,  $ip )");

        $return_text = $recommendNew .     . $irt_textOnclick;
        echo $return_text; //$recommendNew; // 
    }
    else {
        $return_text = $recommend .     . $irt_textOnclick;
        echo $return_text; //$recommendNew; //  
    }
}
问题回答

如果您同时使用 cookie 和 IP 检查来阻止多次投票,那么对于共享同一 IP 地址的计算机,投票不能超过一次。 这将阻止同一网络的其他用户投票,因为您将被视为拥有一个 IP 地址 。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签