dousong9729 2012-07-18 12:50
浏览 43

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

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条回答 默认 最新

  • drgc9632 2012-07-18 13:43
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 数学的三元一次方程求解
  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题