plugin development - Counter not working correctly

<?phpfunction ip_get(){if(!empty($_SERVER['HTTP_CLIENT_IP'])){ip from share internet$new_ip = $_SERVER[&#

<?php


function ip_get(){

    if(!empty($_SERVER['HTTP_CLIENT_IP'])){
        //ip from share internet
        $new_ip = $_SERVER['HTTP_CLIENT_IP'];
    }elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
        //ip pass from proxy
        $new_ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }else{
        $new_ip = $_SERVER['REMOTE_ADDR'];
    }


global $wpdb;
    $table_name=$wpdb->prefix.'wbs_user_ips';

    $results = $wpdb->get_results( "SELECT * FROM $table_name"); // Query to fetch data from database table and storing in $results
if(empty($results)){
    $wpdb->insert($table_name,
    array(
          'user_ip'=>$new_ip,      
          'user_count'=>'1',      
          'user_status'=>'0',    

    )
    );
}
    if(!empty($results))                        // Checking if $results have some values or not
{  
    $count=0;
foreach($results as $row){

   $ip= $row->user_ip;
 $count=$row->user_count;

}


if($ip==$new_ip){
    echo $count++;

    $wpdb->query($wpdb->prepare("UPDATE $table_name 
                SET user_count=".$count."
                WHERE user_ip = %s",$ip));
}




}

}
?>

when i run the plugin count variables increment 4 times or 5 time can you please help me

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745321025a4622442.html

相关推荐

  • plugin development - Counter not working correctly

    <?phpfunction ip_get(){if(!empty($_SERVER['HTTP_CLIENT_IP'])){ip from share internet$new_ip = $_SERVER[&#

    6小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信