从html和javascript访问经过身份验证的php页面

我正在尝试编写一个简单的html页面来创建两个数据源的mashup。 其中一个数据源是一个PHP页面,每次请求时都会生成一个Google Earth KMZ文件。 我的目标是在“实时”页面上的地图上显示此Feed。</ p>

特定的PHP页面需要身份验证,我有用户名和密码。 当我将URL插入Web浏览器时,它会询问我的凭据,我提供它们并下载KMZ文件。</ p>

我想让我的html页面使用javascript来制作HTTP 请求PHP页面,检索返回的KMZ并将其加载到地图上。</ p>

我对这类事情完全不熟悉,所以如果我要前往此,请告诉我 正确的方向,这可能吗?</ p>
</ div>

展开原文

原文

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?

1个回答

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.

dongshao8471
dongshao8471 谢谢@Remco - 我不确定使用什么类型的身份验证。 我尝试了你描述的两种方法,它仍然弹出一个询问用户名和密码的方法。 第一种方法首先告诉我,我试图登录不需要身份验证的站点。 这可能是因为域本身不需要身份验证,但php页面呢?
8 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐