No me funciona file_get_contents

no me sirve este codigo en el servidor online

$search_url = “http://nominatim.openstreetmap.org/search?q=colombia&format=geojson”;

    $httpOptions = [
        "http" => [
            "method" => "GET",
            "header" => "User-Agent: user"
        ]
    ];
    
    $streamContext = stream_context_create($httpOptions);
    $json = file_get_contents($search_url, false, $streamContext);

Your example works for me. What is the error-message you’re getting? In order to open a URL with file_get_contents(), the allow_url_fopen option must not be false in the php.ini. If you’re running this on some shared hosting server, your provider might have disabled this. Care to post the error-message?

I am executing it in “000webhostapp.com” it does not show me any error when I debug it with print_r (file_get_contents), but in the local server it shows all the content,
It is as if openstreetmap were blocking the requests from this host, I say this because from other pages if the normal content arrives with that same code

I’d highly recommend to familiarise yourself with Nominatim Usage Policy (aka Geocoding Policy)

2 Likes

$search_url = “http://api.positionstack.com/v1/forward?access_key=(+++your api key+++)&query=colombia&bbox_module=1”;

thanks for your time, you can solve with this other page