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 6237897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:06:55+00:00 2026-05-24T11:06:55+00:00

I use a javascript API from (http://www.iplocationtools.com) to give me the location data from

  • 0

I use a javascript API from (http://www.iplocationtools.com) to give me the location data from a visitors IP. For some reason, their API won’t give me the actual IP of the visitor, just the other info, which is why I have to use PHP and CodeIgniter to give me the IP instead.

So I use CodeIgniter/PHP to get the IP of a visitor and add it to the database along with location data from above by using PHP’s ip2long([the ip code igniter gives me])

I’m confused when my database table looks like this: http://pulse.media.mit.edu/images/1.png

Which is wrong? I’m tempted to believe CodeIgniter is wrong since it gives me the same IP so many times. Age and sex are self reported and I doubt one person is making up all this information.

At the end of the day, all we really need is the users IP and location, preferably from the same source, so we don’t compound errors.

Anybody have a better idea on how to do this?

EDIT: Here is the code that I’m using to get the IP address from CodeIgniter

$data['ip_address'] = ip2long($this->input->ip_address());
$this->pulse_model->voter_info($data);

Then the voter_info function just inserts it into the database where it’s stored as an INT(11).

And here is the function ip_address:

function ip_address()
{
if ($this->ip_address !== FALSE)
{
return $this->ip_address;
}

    if (config_item('proxy_ips') != '' && $this->server('HTTP_X_FORWARDED_FOR') && $this->server('REMOTE_ADDR'))
    {
        $proxies = preg_split('/[\s,]/', config_item('proxy_ips'), -1, PREG_SPLIT_NO_EMPTY);
        $proxies = is_array($proxies) ? $proxies : array($proxies);

        $this->ip_address = in_array($_SERVER['REMOTE_ADDR'], $proxies) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
    }
    elseif ($this->server('REMOTE_ADDR') AND $this->server('HTTP_CLIENT_IP'))
    {
        $this->ip_address = $_SERVER['HTTP_CLIENT_IP'];
    }
    elseif ($this->server('REMOTE_ADDR'))
    {
        $this->ip_address = $_SERVER['REMOTE_ADDR'];
    }
    elseif ($this->server('HTTP_CLIENT_IP'))
    {
        $this->ip_address = $_SERVER['HTTP_CLIENT_IP'];
    }
    elseif ($this->server('HTTP_X_FORWARDED_FOR'))
    {
        $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }

    if ($this->ip_address === FALSE)
    {
        $this->ip_address = '0.0.0.0';
        return $this->ip_address;
    }

    if (strpos($this->ip_address, ',') !== FALSE)
    {
        $x = explode(',', $this->ip_address);
        $this->ip_address = trim(end($x));
    }

    if ( ! $this->valid_ip($this->ip_address))
    {
    $this->ip_address = '0.0.0.0';
    }
    return $this->ip_address;
}
  • 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-24T11:06:56+00:00Added an answer on May 24, 2026 at 11:06 am

    Based on your code, it looks like $this->input->ip_address() has the possibility of returning ‘0.0.0.0’ if the IP is not valid or could not be determined. However, your comments also state that you need to record the ip address even if the above method returns ‘0.0.0.0’.

    First, I’d recommend checking to see if $this->input->ip_address() and $this->valid_ip() are working as expected. Is $this->valid_ip() returning false for IP’s that should be considered valid?

    Second, I’d update your code to always fall back to $_SERVER['REMOTE_ADDR'] if $this->input->ip_address() returns ‘0.0.0.0’.

    $ip_address = $this->input->ip_address();
    if($ip_address == '0.0.0.0') {
        $ip_address = $_SERVER['REMOTE_ADDR'];
    }
    $data['ip_address'] = ip2long($ip_address);
    $this->pulse_model->voter_info($data);
    

    Or if you wanted, you could not use $this->input->ip_address() and do as @rockerest suggests and just use $_SERVER['REMOTE_ADDR'] to being with.

    $data['ip_address'] = ip2long($_SERVER['REMOTE_ADDR']);
    $this->pulse_model->voter_info($data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have included jquery and jqueryui from google api as follows <script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js></script>
I want to use javascript to insert some elements into the current page. Such
I'm trying to use late binding to connect to a COM automation API provided
I'm using the FireFox API to write to a binary file from my JavaScript
I'm using the flikr badge code (http://www.flickr.com/badge_code_v2.gne) like so <!-- Start of Flickr Badge
I'd like to use JavaScript to calculate the width of a string. Is this
Can I use JavaScript to check (irrespective of scrollbars) if an HTML element has
I would like to use javascript to develop general-purpose GUI applications. Initially these are
I would like to use JavaScript to manipulate hidden input fields in a JSF/Facelets
Can I use javascript in a page to cause an event in a silverlight

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.