[SOLVED] [Nominatim] Right way to query from PHP?

Hello,

I can’t figure out the right way to query Nominatim from PHP:

<?php

function getAddressThroughFileGetContents ($RG_Lat,$RG_Lon) {

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

	// Open the file using the HTTP headers set above
	$query = "https://nominatim.openstreetmap.org/reverse?format=json&lat=".$RG_Lat."&lon=".$RG_Lon."&zoom=27&addressdetails=1&email=j.doe@acme.com";
	
	//Warning: file_get_contents(https://...@acme.com): failed to open stream: Connection timed out in /var/www/sda/4/0/myserver/myscript.php on line 47
	$result = file_get_contents($query, false, $context);
	return $result;
}

$lon = 1.23;
$lat = 4.56;
$addr = getAddressThroughFileGetContents($lat,$lon);
echo "Address: ".$addr;

?>

Am I missing yet another required parameter in the URL?

Thank you.

Please show the result of your query - or any error message.

Regards
walter

It’s in the comment. All I get is this:


Warning: file_get_contents(https://...@acme.com): failed to open stream: Connection timed out in /var/www/sda/4/0/myserver/myscript.php on line 47

FWIW, it’s on a shared web server, and allow_url_fopen is ON for Local and Master.

Same issue if I use the EasyPHP server installed on my very own computer:


Warning: file_get_contents(https://...@acme.com): failed to open stream: No error in C:\Program Files\EasyPHP-Devserver-17\eds-www\myscript.php on line 67

Since the query works fine when copy/pasted in a web browser, it looks like Nominatim expects something else when using the PHP script above.


Edit:

For others’ benefit: The code works fine with Xampp (7.2.9)

I’ll see if there’s a lighter, free web + PHP server for Windows (Xampp install file = 124MB!).

HTH,