Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+4 votes
957 views
in Q2A Core by
When I create a new user on my website, the IP address that it shows is the same as my hosting provider, not my local machine.  Im not using any proxy servers or anything like that.  Not sure what is causing it.
Q2A version: 1.7.5
by
+1
Which php and mysql version you are using. is it shared hosting or dedicated server?
by
+1
PHP version 7.0.24
MySQL version 10.1.28-MariaDB
It is shared hosting
by
+1
Normally this can happen because of firewall.  Can you check with your hosting provider if they use such thing before getting traffic to site.

1 Answer

+1 vote
by
edited by

try this solution for this problem

all you have to do is to edit the qa-base.php you can find the file in: (qa/qa-include/qa-base.php)

and search for function qa_remote_ip_address()

and replace this lines 

{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
 return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
}

with this lines

{
    $ipaddress = '';
    if (getenv('HTTP_CLIENT_IP'))
        $ipaddress = getenv('HTTP_CLIENT_IP');
    else if(getenv('HTTP_X_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
    else if(getenv('HTTP_X_FORWARDED'))
        $ipaddress = getenv('HTTP_X_FORWARDED');
    else if(getenv('HTTP_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_FORWARDED_FOR');
    else if(getenv('HTTP_FORWARDED'))
        $ipaddress = getenv('HTTP_FORWARDED');
    else if(getenv('REMOTE_ADDR'))
        $ipaddress = getenv('REMOTE_ADDR');
    else
        $ipaddress = 'UNKNOWN';
    return $ipaddress;
}

by
Thank you. I'm getting a public IP and a local IP separated by comma. How do I get only the public IP?
by
i'm sorry if i'm late to answer
but HTTP_X_FORWARDED_FOR sometimes returns internal or local IP address, which is not usually useful. Also, it would return a comma separated list if it was forwarded from multiple ip addresses.
try to remove this lines

 else if(getenv('HTTP_X_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_X_FORWARDED_FOR');

and tell me
by
Teneff's answer in this post solved it for me: https://stackoverflow.com/questions/13646690/how-to-get-real-ip-from-visitor

Thank you for your time.
...