0

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?

Brian
  • 2,702
  • 5
  • 37
  • 71

1 Answers1

0

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 username
  • password the actual password
  • host.name the address of the remote server,
  • file.name the PHP file you are trying to access
  • optional: parameter=x any known parameters required to get the required output from the PHP file

PHP 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&parameter=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.

Community
  • 1
  • 1
Rem.co
  • 3,813
  • 3
  • 29
  • 37
  • Thanks @Remco - I'm not sure what type of authentication is used. I tried both methods you described and it still gave me a pop up asking for username and password. The first method first told me that I was attempting to log into a site that does not require authentication. Could this be because the domain itself does not require authentication, but the php page does? – Brian Jul 18 '12 at 14:31