Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Authentcate Directory in PHP

Status
Not open for further replies.

roytheboy

Programmer
Aug 18, 2002
58
GB
I am setting up a system that will manage access to a collection of IP cameras for the web.

the database is fine...i dont have anyproblems with that.

however the inbuilt webserver has a directory /img and /admin....that when you try to view any content in there e.g. video.asf... you prompted wihtin login and password.

i want to hard docde this into my php scripts so that i do not get prompted as my security will lie within my database.

please help.... very stuck.... because this is a webserver on the camera i cannot make a change ot her webserver :(

summary:

how do i pass a username and password to authenticate the directory so taht wheni stream the video.asf file i can see it.

thanks i advance guys and gals

Romolo & Creepy (JUST FRIENDS) :)
 
That authentication is being enforced by your webserver. In apache it's probably done with .htaccess files in those directories, removing them would get rid of the authentication.
 
I can't remove the .htaccess file, because it is not my own webserver. I want to access a Webserver on a webcam.

I have read the article at php.net, but I have only found a description which explains how to ask a user for an username and a password.

I would like to know, how can I prompt a username and password for a basic Http authentication. There should be no dialog, which asks the user for a username and password.

Can you help me????
Thanks!
 
Look at the HTTP Authorization header definition:
The HTTP/1.0 specification defines the BASIC authorization scheme, where the authorization parameter is the string of username:password encoded in base 64. For example, for the username of "webmaster" and a password of "zrma4v," the authorization header would look like this:

Authorization: BASIC d2VibWFzdGVyOnpycW1hNHY=

The value decodes into webmaster:zrma4v.
 
If you are on windows you could use msxml (via the comm interface) which has a handy username and password parameter.
failing that (and I've never used it) you might be able to supply the username and passwiord with curl
 
<?php
$http_response = '';

$fp = fsockopen('195.147.83.185',2000);
fputs($fp, "GET /img/video.asf HTTP/1.1\r\n");
fputs($fp, "Host: ***.***.***.***:****\r\n");
fputs($fp, "Connection: Keep-Alive\r\n");
fputs($fp, "Authorization: Basic YWRtaW46YWRtaW4=\r\n\r\n");

while (!feof($fp) && (strlen($http_response)<100))
{
$http_response .= fgets($fp, 60);
}
echo $http_response."<br>";

?>

This is the solution to access the protected stream file, but I still have a problem.

The video player is a ocx file, which tries to access the stream on its own. The problem is that it doesn't send the string "Authorization: Basic YWRtaW46YWRtaW4=" to the webserver of the camera. Therefore it can't access the stream.

Normally the browser saves the username and the password, when the user has filled in them. Therefore the browser always sends the string "Authorization: Basic YWRtaW46YWRtaW4=" to the webserver, when it sends a new request to webserver.

My question is: How can I inform the browser about the username and password????

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top