• Resolved Kim

    (@spacewell)


    I’m trying to build some scripts showing a user the time of an online event according to the timezone he is in.

    It seems geoip_detect2_get_info_from_current_ip() is returning the same data no matter where the user is. I tested using VPN, Geoscreenshot.com and asked colleague in India and the US. The date retuned is the same everywhere.

    I was assuming it was caused by caching but turning off the caching plugin (WP Rocket) completely does not seem to solve the issue.

    • This topic was modified 5 years, 8 months ago by Kim.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Kim

    (@spacewell)

    At first I used the function like this:
    $userInfo = geoip_detect2_get_info_from_current_ip();

    But then I found t should probably be:

    $ip = geoip_detect2_get_client_ip();	
    $userInfo = geoip_detect2_get_info_from_current_ip($ip);

    Echoing out geoip_detect2_get_client_ip() now shows the same IP address everywhere.

    This is what the Client IP Debug Panel shows:

    Current IP informations (as detected by the plugin)
    Detected client IP: 10.10.4.252
    This IP is used for detecting the geo-information of the user. It should be the same as the real client IP below.
    Real client IP (detected without the plugin): Failed: error
    This IP is detected within the browser, so reverse proxies of the server are not affected.
    External Server IP: 81.246.42.197
    In some cases, the server is in the same network as the client (e.g. testing server). As the connection does not use Internet, this plugin uses the IP adress of the server as seen from the internet.
    For performance reasons, this IP is cached for 2 hours.
    Also, for servers without internet access, this IP can be set in the options.
    REMOTE_ADDR: 10.10.4.252
    In server configurations without reverse proxy, this will equal to the “detected client IP”. Otherwise, this is the IP of the reverse proxy.
    HTTP_X_FORWARDED_FOR: (unset)
    Reverse proxies usually add this header to indicate the original IP. If several IPs are given here (seperated by a comma), the correct user IP usually is the leftmost one.
    Settings of the plugin
    Use reverse proxy: no
    Enable this option if REMOTE_ADDR is not the correct client IP.
    Whitelist for known reverse proxies (optional if only one): (none)
    All IPs in HTTP_X_FORWARDED_FOR that are not the correct client IP are probably known reverse proxies.
    (For security reasons, this is not assumed by default: maybe the reverse proxy is not of the server, but a Man-In-The-Middle-Attack … not very probable but possible.)

    What am I missing here?

    • This reply was modified 5 years, 8 months ago by Kim.
    • This reply was modified 5 years, 8 months ago by Kim.

    geoip_detect2_get_info_from_current_ip() is equivalent to the other lines you mentioned.

    10.10.4.252 is a private IP which does not have geolocation information attached, so the plugin will get the geoinformation from the server IP (81.246.42.197) instead.

    If local time is the only reason you are using the plugin, it would be much more useful & more exact to use the JavaScript time functions instead of the plugin – as some users might have set their computer to use a different timezone than the one detected by IP (e.g. tourists or in case the IP has no geolocation data attached), and this is known by the browser, but not the server. For example:

    https://stackoverflow.com/questions/6525538/convert-utc-date-time-to-local-date-time?lq=1

    Thread Starter Kim

    (@spacewell)

    Thanks very much Benjamin.

    Auch, I was going at it completely wrong. Thanks for the tip!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Plugin returns same geo data anywhere’ is closed to new replies.