NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

I used in a PHP script to call the Nominativ API with file_get_contents. This worked excellently until 13.09.2017.

I have tried CURL but no result or error returns.

function file_get_contents_curl($cmd, $query) {
$ch = curl_init();
$query= curl_escape($ch,$query);
$url = $cmd.$query;
echo $url.' <--';
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
//Set curl to return the data instead of printing it to the $
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);       
$data = curl_exec($ch);
return $data;


/*result of echo

Can anyone help me with a working solution?

asked 23 Sep '17, 06:22

user_5359's gravatar image

accept rate: 0%

edited 23 Sep '17, 13:58

Richard's gravatar image

Richard ♦

PHP's file_get_contents() sends neither HTTP UserAgent nor Referer, which violates the usage policy for the server. You can easily add custom HTTP headers by creating an appropriate stream context like that:

// Create a stream
$opts = array('http'=>array('header'=>"User-Agent: StevesCleverAddressScript 3.7.6\r\n"));
$context = stream_context_create($opts);

// Open the file using the HTTP headers set above
$file = file_get_contents('', false, $context);

For more information see the PHP user manual.

permanent link

answered 24 Sep '17, 15:58

lonvia's gravatar image

accept rate: 40%

Do you run the script within the limits, e.g. Number of requests per second? I see the email parameter is a non-existing email. It's possible you got blocked. That would explain why it stopped working from one day to the next.

permanent link

answered 23 Sep '17, 08:48

mtmail's gravatar image

accept rate: 27%


the email address has been changed for security reasons. If I'm blocked, I would get a corresponding HTML text.

Unfortunately, the code runs on my development machine, but not on the server. In which direction do I have to see which parameters (CURL installation?) can have an effect?

(23 Sep '17, 11:22) user_5359

I had a similar problem while acquiring coordinates for geocoding. I need to add also my email address to url. I combined info from this: link text and this: link text to get this:

        $url = ''.rawurlencode($location).'?format=json&limit=1&';

        $data = ''; // empty post
        $opts = array(
            'http' => array(
            'header' => "Content-type: text/html\r\nContent-Length: " . strlen($data) . "\r\n",
            'method' => 'POST'
        // Create a stream
        $context = stream_context_create($opts);
        // Open the file - get the json response using the HTTP headers set above
        $jsonfile = file_get_contents($url, false, $context);
        // decode the json 
        if (!json_decode($jsonfile, TRUE)) {return false;}else{
        //if (empty(array_filter($resp))) {return false;}else{
        $resp = json_decode($jsonfile, true);
        //if(is_string($resp)){$resp = 'true';}else{$resp = 'itsnot';}
        // Extract data (e.g. latitude and longitude) from the results    
        $gps['latitude'] = $resp[0]['lat'];
        $gps['longitude'] = $resp[0]['lon'];
        return $gps;}
permanent link

answered 31 Jul '18, 01:21

Pablo's gravatar image

accept rate: 0%

Cool, thanks to lonvia here's a practical example to get around this nonsense with php. Using the browsers user_agent as a variable.

function OsmAddress() {
    $Latitude ='22.56589015';
    $Longitude ='113.9259518';

    $opts = array('http'=>array('header'=>"User-Agent: $USERAGENT\r\n"));
    $context = stream_context_create($opts);
    $url4 = file_get_contents("$Latitude&lon=$Longitude&zoom=18&addressdetails=1", false, $context);
    $osmaddress = json_decode($url4);  
    $osmaddress1 = $osmaddress->display_name;
    echo $osmaddress1;
permanent link

answered 02 Dec '18, 07:35

J0naz's gravatar image

accept rate: 0%

So you are re-using/faking the user's useragent for your server-side script to execute a nominatim query on the user's behalf? Not sure if that is a good idea with regards to complying with . Do not be surprised if your access will be blocked at some point in time. I guess that setting a proper referer, custom user agent (your application's name) a contact email address would be a better way to go.

Note that to get around that "nonsense" you are free (and very welcome) to set up your own nominatim service using our free data.

(02 Dec '18, 11:14) aseerel4c26 ♦

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 23 Sep '17, 06:22

question was seen: 15,456 times

last updated: 02 Dec '18, 11:15

NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum