I am trying to write a simple html page to create a mashup of two data feeds. One of the data feed sources is a PHP page that produces a Google Earth KMZ file each time it is requested. My goal is to display this feed on a map on my page in 'real-time'.
The particular PHP page requires authentication and I have the username and password. When I plug the URL into a web browser it asks for my credentials, I provide them and it downloads a KMZ file.
I would like to have my html page use javascript to make the HTTP Request to the PHP page, retrieve the returned KMZ and load it on the map.
I am completely new to this sort of thing, so please let me know if I'm headed in the right direction and is this possible?
You don't specify which type of authentication is being used on the remote side, hence, I'm going to make some guesses and assumptions:
Basic HTTP Authentication
If "Basic HTTP Authentication" is used (Which would show a browser pop-up requesting username/password for the realm), you can formulate your request URL as follows:
http://username:password@host.name/file.name?parameter=x
Where:
username
is your actual known usernamepassword
the actual passwordhost.name
the address of the remote server,file.name
the PHP file you are trying to accessparameter=x
any known parameters required to get the required output from the PHP filePHP Authentication
If the actual authentication is done by the PHP page itself it's a different story. In that case it all depends on which variables the PHP script uses to perform authentication, specifically which type of parameter. Most commonly GET
or POST
are used (or if REQUEST
is used, both will work).
Either way, you will have to know the name of the parameter that is being used. I'm going to assume user
and pass
for the examples below.
In the PHP script these will look like $_GET['user']
, $_POST['user']
, $_REQUEST['user']
or simply $user
if the dangerous register_globals is set in php.ini
.
In case of GET
or REQUEST
:
http://host.name/file.name?user=username&pass=password¶meter=x
In case of POST
:
It is possible to POST
values using JavaScript. This SO answer gives a working examle.
Anything else
If any other method (and there are plenty others) is used, more specific information is required to determine the exact method and a working solution.