Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show an image which is secured by http authentication

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

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.

like image 252
user3053216 Avatar asked Jun 04 '14 16:06

user3053216


People also ask

How do I get HTTP authentication?

HTTP basic authentication is a simple challenge and response mechanism with which a server can request authentication information (a user ID and password) from a client. The client passes the authentication information to the server in an Authorization header. The authentication information is in base-64 encoding.

What is HTTP authentication method?

HTTP Authentication is a security mechanism to verify the user who is eligible to access the web resource. It involves communication between client and server using HTTP header where server requests user's credentials for authentication. The client in response provides the information in the header.

Does HTTP provide authentication?

HTTP provides a general framework for access control and authentication.

How does HTTP handle user authentication information?

The HTTP protocol supports authentication as a means of negotiating access to a secure resource. The initial request from a client is typically an anonymous request, not containing any authentication information. HTTP server applications can deny the anonymous request while indicating that authentication is required.


2 Answers

This should work. Simply replace the username and password with your authentication details. (Warning: Doesn't work in all browsers)

<img src="http://username:password@server/Path" />

I would recommend putting this in a separate file on your server. That way you can reference it without exposing the authentication info.

like image 55
Brobin Avatar answered Oct 06 '22 00:10

Brobin


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;
?>

Then use

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

To get the image.

like image 27
user3053216 Avatar answered Oct 05 '22 23:10

user3053216