如何显示通过http认证保护的图像 [英] How to show an image which is secured by http authentication

查看:146
本文介绍了如何显示通过http认证保护的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用标准http保护服务器显示图片而不显示认证窗口?

How can i show an image from a server with standard http protection without showing the authentication window?

我现在使用标准html

I now use standard html

<img src="...">

但由于图像受到保护,因此要求输入验证窗口。我有登录数据,如何显示图像?

but because the image is protected this asks for an authentication window. I do have the login data, how can i show the image?

Regards,Tom。

Regards, Tom.

推荐答案

一个办法。它适用于所有浏览器。 script.php是

I used IrishGeeks tip to get a solution. It works on all browsers. The script.php is

<?php
$url    = $_GET['url'];
$c = curl_init($url);
$authString = 'user:pass';
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_USERPWD, $authString);

$content = curl_exec($c);
$contentType = curl_getinfo($c, CURLINFO_CONTENT_TYPE);
header('Content-Type:'.$contentType);
print $content;
?>

然后使用

<?php
print '<img src="script.php?url='.urlencode('http://www.example.com/image.bmp').'" />';
?>

获取图片。

这篇关于如何显示通过http认证保护的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆