Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6786007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:11:41+00:00 2026-05-26T17:11:41+00:00

I have set up a polling system on my website. However to ensure that

  • 0

I have set up a polling system on my website. However to ensure that people cannot vote again, I have a IP finding mechanism to gather their IP and to make sure that they do not vote again.

The way in which i do this, is I gather their IP then compare it to a text file which has the IP in it. It has a comma to separate each IP.

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

$visitorIp = getUserIP();
$myFile = "ip_polllist.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, 200);
fclose($fh);
$findme = $visitorIp.",";
$mystring = $theData;
echo $mystring;
echo $findme;
$pos = strpos($mystring, $findme);
if($pos === true)
{
    die();
}
if($pos == true)
{
die();
}

What is wrong with the code and why does $pos = false?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:11:42+00:00Added an answer on May 26, 2026 at 5:11 pm

    I don’t think your approach is really good:

    1) It is not really good to write to a single file from multiple requests, because the looking of the file might decrease the performance of your script. Don’t you have access to any database system?

    2) Do you have any account system on your page? If yes, I would prefer to restrict a second vote based on the account rather than on the IP address.

    3) What do you do when you start a second poll? Create a second file?

    4) fread($fh, 200): What happens if you have 100 locked users (IPs)? Your script only reads the first 200 bytes.

    5) if($pos == true): I really don’t like relying on the autocasting “feature” of PHP. You are expecting FALSE or a number so check for FALSE and >= 0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have setup a polling system, where when you vote it stores your external
I have a system set up currently that is using celery with a redis
I have a project that I've been working on called system that I set
I have set the eclipse java formatter to wrap lines that exceed 120 characters
I have set up an app that is registered for remote notifications. - (void)application:(UIApplication*)application
I'm writing a top 10 polling system. Pollsters vote weekly on their top 10.
I have a comboBox that has a datatrigger that set its SelectedIndex based on
We have a Rails application that is running in a MySQL master-slave set-up for
I have the PHP/MySQL done for a polling system. It pretty simple, basically the
I have an asp.net application that utilizes long polling. So, a typical call to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.