Skip to content

Instantly share code, notes, and snippets.

@gruessung
Created April 5, 2018 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gruessung/ed45b84a1a93b0b7372415f751c16602 to your computer and use it in GitHub Desktop.
Save gruessung/ed45b84a1a93b0b7372415f751c16602 to your computer and use it in GitHub Desktop.
OSM PHP Cache
<?php
if (strpos($_SERVER['HTTP_REFERER'], 'yourdomain.com') === false) {
header('HTTP/1.0 403 Forbidden');
die('forbidden for '.$_SERVER['HTTP_REFERER']);
}
header('Access-Control-Allow-Origin: *');
$sSub = $_GET['sub'];
$iZ = $_GET['z'];
$iY =$_GET['y'];
$iX = $_GET['x'];
$sFormat = $_GET['format'];
$sShort = $iZ.$iX.$iY.$sSub.'.'.$sFormat;
if (!file_exists('cache/'.$sShort)) {
$sOSMFile = file_get_contents('https://'.$sSub.'.tile.openstreetmap.org/'.$iZ.'/'.$iX.'/'.$iY.'.'.$sFormat);
if ($sOSMFile == false) {
header('HTTP/1.0 404 Not found');
die('');
}
file_put_contents('cache/'.$sShort, $sOSMFile);
}
echo file_get_contents('cache/'.$sShort);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment