Check if a user already voted

I’m writing a WordPress poll system. I need to check if a user already voted, show him/her a message. But i dont know exactly how can i do that!
One of my solutions is that to creating a table (named wp_voters) and entering each user’s ip and poll id.

$user_ip = $_SERVER['REMOTE_ADDR'];

But it doesn’t realy work. For a single user, It assigns two or more ip addresses.
How can i handle this problem?
thanks,

Solutions Collecting From Web of "Check if a user already voted"

Creating a table for such functionality in WordPress is not an efficient move. I would prefer to do this using follwoing approach.

  1. Create Custom post type for your voters info. For this you can try Generate WP post type generator.

  2. When ever user visits your site; save IP and rating in post meta using wp insert post and add_post_meta. In this way you will be able to view the list in back-end as well.

  3. Every time when user visits your site check if there is some user with that IP using WP Query. If it exist no need to add info else add his info using step 2.

Here is a simple function to get ip of your user;

function get_the_user_ip() {

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

    return $ip;

} 

Hope this might work for you.