Index.php fail to populate geo location info

Gist of index.php

Requesting help troubleshooting.

William

1 Like

Hi, thank you for posting in the community. Can you be a bit more specific about the issue and provide further details, please?

Until a few days ago “index.php” was working; now throwing a couple of errors:

Warning : file_get_contents(http://ipinfo.io/2601:803:c600:a7f:dd6e:220c:190e:e0d5/json?token=mytoken): failed to open stream: Network is unreachable in /storage/ssd3/644/18898644/public_html/index.php on line 66

Notice : Undefined index: HTTP_REFERER in /storage/ssd3/644/18898644/public_html/index.php on line 87

William

Our engineer has provided the following context:

The error indicates a network issue, and they’re using 000webhost which is a free website host (that has been around since… the beginning of time) which is unreliable (due to the free nature, lots of abuse, no SLA).

The ideal step would be to run some network checks from the server, but the user won’t have access to do that, so best option is to either:

  1. ask their host to investigate (unlikely to offer support)
  2. try an alternate address (e.g: https://v6.ipinfo.io/ )
  3. switch to a better host (e.g: fly.io has a free plan and won’t have these issues)

just saying, you leaked your token there, you should probably change it:)

1 Like

I no longer have network unreachable; however, referer, City, Region,and Country are not populating.

Updated php Gist

I have posted to ooowebhost discord channel; awaiting their resonse, have opened support ticket.

William

1 Like

Im honestly not sure what your problem is.


seems to be working fine and as expected for me with the gist you sent.
Maybe explain the issue a little more closely?

Thank you hibenji for the report that the Gist is working for you.

The php script worked good up until about the end of October; has been online since 2017, providing Referer, City, Region, and Country.

Will try thethered network connection and a new token. It is like I have been banned at ipinfo.io.

William

Yeah, maybe just try using curl with your ip and token and see if that works. Or print the entire response to the page to see the response and error:D

Benji

Entering my ipAddress manually; I get expected results:

Manually entered ipAddress

{$_SERVER[‘REMOTE_ADDR’]} does not capture ipAddress.

Is there a syntax error?

William

It’s possible that is something in your configuration that is wrong, I would recommend enable error output for your site by adding these two lines at the top of your php.

<?php
error_reporting(E_ALL); // Report all types of errors
ini_set('display_errors', 1); // Display errors on the web page
?>

Then just reload your page and you should be able to see what the issue is and why your ip isn’t populating correctly.

Benji

Result of adding above code:

William

seems like like your provider has some issues, maybe blocking outgoing connections?

if you want, you can try using curl since that should give you a little more info, but its most likely your provider blocking those connections. (maybe they are also only blocking ipinfo, though that would be weird.)

// The URL you want to send the GET request to
$url = "http://example.com";
// Initialize a cURL session
$ch = curl_init();
// Set the URL for the cURL session
curl_setopt($ch, CURLOPT_URL, $url);
// Return the transfer as a string instead of outputting it
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute the cURL session and fetch the response
$response = curl_exec($ch);
// Check for errors and display the error message
if(curl_errno($ch)){
    echo 'Request Error:' . curl_error($ch);
} else {
    // Print the response if the request was successful
    echo $response;
}
// Close the cURL session
curl_close($ch);

Benji

Added code; plus changed url to v6.info.io. Some success…

William

Seems like something worked at the top there?
Was that the curl request? If yes, just use that and change your code a little use the curl request instead.

Yes, that was a curl url.

How can this be coded to use ip from browser? I do not program in php or know how to switch to curl. Requesting help with conversion.

William

If you want I’ll change it out tomorrow, just send me a link to your code and I’ll switch it out, it’s just a few lines of code in the end:)

Benji

Thank you hibenji; I used ChatGPT to conert my code to use Curl.
Have Curl code working!!!

Thank you for all your help with this issue.

William

Wonderful, happy to help and good luck with your future endeavors:)