Open a KMZ file in google maps, but only for trusted (authenticated) users in PHP

StackOverflow https://stackoverflow.com/questions/23559705

  •  18-07-2023
  •  | 
  •  

Pergunta

I know that it's possible to open a KMZ or KML file in browser with google maps with an url like this:

https://maps.google.it/maps?q=http://myserver.com/mymap.kmz

But I would like to let only authenticated users open that kmz. To do that, I protected my kmz folder with .htaccess, I coded a php page that checks if the user is logged in and only after that check is passed, it returns the kmz file:

...
if(isset($_SESSION['trusted'])) {
    if(isset($_GET['map']) && $_GET['map']!="") {
        $map = $_GET['map'];
        readfile("./kmz/$map");
}
...

So, now my url is:

https://maps.google.it/maps?q=http://myserver.com/requestkmz.php?map=mymap.kmz

The problem seems to be that the file that php returns with readfile is not identical to the original one in file system. Do I need to put an header or specify an encoding?


UPDATE

I've added an header to the php file, but I've got the same result: KMZ generated is not valid as is the orginal. This is the header added before the readfile line:

header("Cache-Control: no-cache, no-store, must-revalidate"); 
header('Content-Type: application/vnd.google-earth.kmz');
header("Content-Disposition: inline");
header("Content-Description: KMZ data intended for Google Earth");
Foi útil?

Solução

The request to the KMZ-file comes from google, not from the user(when you take a look at console->network you'll see that there isn't any request to the KMZ-file).

So the only "user" that needs to be authorized is google.

Means: it's not possible(except you pass the credentials needed to authenticate the user via the KMZ-URL, but this of course would be insecure )

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top